]> git.saurik.com Git - cycript.git/commitdiff
Implemented functor caching.
authorJay Freeman (saurik) <saurik@saurik.com>
Thu, 19 Nov 2009 21:44:34 +0000 (21:44 +0000)
committerJay Freeman (saurik) <saurik@saurik.com>
Thu, 19 Nov 2009 21:44:34 +0000 (21:44 +0000)
Bridge.sh
Execute.cpp
Execute.hpp
Pooling.hpp

index c8470954fbef0c278854ca08988c4117e9983f4e..a090547442b1a9b704aac3f7589549c4486c55ff 100755 (executable)
--- a/Bridge.sh
+++ b/Bridge.sh
@@ -19,11 +19,12 @@ cat << EOF
 struct CYBridgeEntry {
     int name_;
     const char *value_;
+    void *cache_;
 };
 
 %%
 EOF
 
-grep '^[CFV]' "$1" | sed -e 's/^C/0/;s/^F/1/;s/^V/2/' | sed -e 's/"/\\"/g;s/^\([^ ]*\) \([^ ]*\) \(.*\)$/\1\2, "\3"/';
-grep '^[EST]' "$1" | sed -e 's/^S/3/;s/^T/4/;s/^E/5/' | sed -e 's/^5\(.*\)$/4\1 i/;s/"/\\"/g' | sed -e 's/^\([^ ]*\) \([^ ]*\) \(.*\)$/\1\2, "\3"/';
-grep '^:' "$1" | sed -e 's/^: \([^ ]*\) \(.*\)/6\1, "\2"/';
+grep '^[CFV]' "$1" | sed -e 's/^C/0/;s/^F/1/;s/^V/2/' | sed -e 's/"/\\"/g;s/^\([^ ]*\) \([^ ]*\) \(.*\)$/\1\2, "\3", NULL/';
+grep '^[EST]' "$1" | sed -e 's/^S/3/;s/^T/4/;s/^E/5/' | sed -e 's/^5\(.*\)$/4\1 i/;s/"/\\"/g' | sed -e 's/^\([^ ]*\) \([^ ]*\) \(.*\)$/\1\2, "\3", NULL/';
+grep '^:' "$1" | sed -e 's/^: \([^ ]*\) \(.*\)/6\1, "\2", NULL/';
index dfe0600d0a2e0bf79dfc1ba74d4dd68c7f3d8938..806fd39f7478e0ef227e5344ffbd1a4f63c4a39f 100644 (file)
@@ -169,7 +169,9 @@ JSStringRef toJSON_s;
 static JSStringRef Result_;
 
 void CYFinalize(JSObjectRef object) {
-    delete reinterpret_cast<CYData *>(JSObjectGetPrivate(object));
+    CYData *internal(reinterpret_cast<CYData *>(JSObjectGetPrivate(object)));
+    if (--internal->count_ == 0)
+        delete internal;
 }
 
 void Structor_(apr_pool_t *pool, sig::Type *&type) {
@@ -486,8 +488,21 @@ JSObjectRef CYMakePointer(JSContextRef context, void *pointer, size_t length, si
     return JSObjectMake(context, Pointer_, internal);
 }
 
-static JSObjectRef CYMakeFunctor(JSContextRef context, void (*function)(), const char *type) {
-    cy::Functor *internal(new cy::Functor(type, function));
+static JSObjectRef CYMakeFunctor(JSContextRef context, void (*function)(), const char *type, void **cache = NULL) {
+    cy::Functor *internal;
+
+    if (cache != NULL && *cache != NULL) {
+        internal = reinterpret_cast<cy::Functor *>(*cache);
+        ++internal->count_;
+    } else {
+        internal = new cy::Functor(type, function);
+
+        if (cache != NULL) {
+            *cache = internal;
+            ++internal->count_;
+        }
+    }
+
     return JSObjectMake(context, Functor_, internal);
 }
 
@@ -954,7 +969,7 @@ static JSValueRef All_getProperty(JSContextRef context, JSObjectRef object, JSSt
 
                 case '1':
                     if (void (*symbol)() = reinterpret_cast<void (*)()>(CYCastSymbol(name.data)))
-                        return CYMakeFunctor(context, symbol, entry->value_);
+                        return CYMakeFunctor(context, symbol, entry->value_, &entry->cache_);
                     else return NULL;
 
                 case '2':
index 6653c9b9d57d1b68787146f37c7643f8cef7a243..922aad44ab005442ed08843fb5d5a57ce4e4562b 100644 (file)
@@ -43,6 +43,7 @@
 struct CYBridgeEntry {
     int name_;
     const char *value_;
+    void *cache_;
 };
 
 extern "C" struct CYBridgeEntry *CYBridgeHash(const char *data, size_t size);
index c9076624e445abdf8d79dde80084b477bf7283cf..a182906e0c9ef343a37e4ed2d135d23bfe2f78e9 100644 (file)
@@ -88,6 +88,12 @@ class CYPool {
 
 struct CYData {
     apr_pool_t *pool_;
+    unsigned count_;
+
+    CYData() :
+        count_(1)
+    {
+    }
 
     virtual ~CYData() {
     }
@@ -107,7 +113,6 @@ struct CYData {
     static void operator delete(void *data) {
         apr_pool_destroy(reinterpret_cast<CYData *>(data)->pool_);
     }
-
 };
 
 template <typename Type_>