[tracker] Improve performance for SparqlBuilder.object_string
- From: Benjamin Otte <otte src gnome org>
- To: svn-commits-list gnome org
- Subject: [tracker] Improve performance for SparqlBuilder.object_string
- Date: Thu, 23 Jul 2009 09:51:04 +0000 (UTC)
commit 0b76a1b75e07cf2db87d9ce543323278d7e58df3
Author: Benjamin Otte <otte gnome org>
Date: Wed Jul 22 19:41:11 2009 +0200
Improve performance for SparqlBuilder.object_string
Don't check characters one-by-one but instead use strcspn to find the
next character to escape. This improves performance for this function
significantly.
src/libtracker-common/tracker-sparql-builder.vala | 15 +++++++--------
1 files changed, 7 insertions(+), 8 deletions(-)
---
diff --git a/src/libtracker-common/tracker-sparql-builder.vala b/src/libtracker-common/tracker-sparql-builder.vala
index d958747..a28e0d5 100644
--- a/src/libtracker-common/tracker-sparql-builder.vala
+++ b/src/libtracker-common/tracker-sparql-builder.vala
@@ -17,6 +17,9 @@
* Boston, MA 02110-1301, USA.
*/
+[CCode (cname = "strcspn", cheader_filename = "string.h")]
+extern static size_t strcspn (string s1, string s2);
+
public class Tracker.SparqlBuilder : Object {
enum State {
UPDATE,
@@ -124,6 +127,9 @@ public class Tracker.SparqlBuilder : Object {
char* p = literal;
while (*p != '\0') {
+ size_t len = strcspn ((string) p, "\t\n\r\"\\");
+ str.append_len ((string) p, (long) len);
+ p += len;
switch (*p) {
case '\t':
str.append ("\\t");
@@ -134,12 +140,6 @@ public class Tracker.SparqlBuilder : Object {
case '\r':
str.append ("\\r");
break;
- case '\b':
- str.append ("\\b");
- break;
- case '\f':
- str.append ("\\f");
- break;
case '"':
str.append ("\\\"");
break;
@@ -147,8 +147,7 @@ public class Tracker.SparqlBuilder : Object {
str.append ("\\\\");
break;
default:
- str.append_c (*p);
- break;
+ continue;
}
p++;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]