[vala] glib-2.0: Improve performance of string.substring on large strings
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] glib-2.0: Improve performance of string.substring on large strings
- Date: Thu, 10 Feb 2011 16:56:02 +0000 (UTC)
commit a2d2120b81361147f3c1451cdf68d873bfd7091a
Author: Jürg Billeter <j bitron ch>
Date: Thu Feb 10 17:55:18 2011 +0100
glib-2.0: Improve performance of string.substring on large strings
vapi/glib-2.0.vapi | 11 ++++++++++-
1 files changed, 10 insertions(+), 1 deletions(-)
---
diff --git a/vapi/glib-2.0.vapi b/vapi/glib-2.0.vapi
index 019339b..291c444 100644
--- a/vapi/glib-2.0.vapi
+++ b/vapi/glib-2.0.vapi
@@ -1277,11 +1277,20 @@ public class string {
[CCode (cname = "g_strndup")]
public string ndup (size_t n);
+ [CCode (cname = "strnlen")]
+ static long strnlen (char* str, size_t maxlen);
[CCode (cname = "g_strndup")]
static string strndup (char* str, size_t n);
public string substring (long offset, long len = -1) {
- long string_length = this.length;
+ long string_length;
+ if (offset >= 0 && len >= 0) {
+ // avoid scanning whole string
+ string_length = strnlen ((char*) this, offset + len);
+ } else {
+ string_length = this.length;
+ }
+
if (offset < 0) {
offset = string_length + offset;
GLib.return_val_if_fail (offset >= 0, null);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]