Did some profiling with OProfile, and found two places where easy gains could 
be had.

- Lauri
From 34cafc51dbfd7e5defa9b06dc41c21039199937e Mon Sep 17 00:00:00 2001
From: Lauri Kasanen <[email protected]>
Date: Wed, 2 May 2012 18:55:19 +0300
Subject: [PATCH 1/2] Add string fast path

This dropped _mk_string_search from 4.5% to 3.5% of Monkey CPU time.

Signed-off-by: Lauri Kasanen <[email protected]>
---
 src/mk_string.c |   19 ++++++++++++++++++-
 1 files changed, 18 insertions(+), 1 deletions(-)

diff --git a/src/mk_string.c b/src/mk_string.c
index 002b0d6..50a1114 100644
--- a/src/mk_string.c
+++ b/src/mk_string.c
@@ -45,6 +45,23 @@ static int _mk_string_search(const char *string, const char 
*search, int sensiti
     char *p = NULL, *q = NULL;
     char *s = NULL;
 
+    // Fast path
+    if (len <= 0) {
+        switch(sensitive) {
+            case MK_STR_SENSITIVE:
+                p = strstr(string, search);
+            break;
+            case MK_STR_INSENSITIVE:
+                p = strcasestr(string, search);
+            break;
+        }
+
+        if (p)
+            return (p - string);
+        else
+            return -1;
+    }
+
     p = (char *) string;
     do {
         q = p;
@@ -66,7 +83,7 @@ static int _mk_string_search(const char *string, const char 
*search, int sensiti
         }
 
         i++;
-        if (len > 0 && i >= len) {
+        if (i >= len) {
             break;
         }
     } while (*p++);
-- 
1.7.2.1

_______________________________________________
Monkey mailing list
[email protected]
http://lists.monkey-project.com/listinfo/monkey

Reply via email to