From: Jay Freeman (saurik) Date: Thu, 19 Nov 2009 21:44:34 +0000 (+0000) Subject: Implemented functor caching. X-Git-Tag: v0.9.432~140 X-Git-Url: https://git.saurik.com/cycript.git/commitdiff_plain/1850a470682f2bbbec1587adacfb1bb4320f30dc Implemented functor caching. --- diff --git a/Bridge.sh b/Bridge.sh index c847095..a090547 100755 --- 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/'; diff --git a/Execute.cpp b/Execute.cpp index dfe0600..806fd39 100644 --- a/Execute.cpp +++ b/Execute.cpp @@ -169,7 +169,9 @@ JSStringRef toJSON_s; static JSStringRef Result_; void CYFinalize(JSObjectRef object) { - delete reinterpret_cast(JSObjectGetPrivate(object)); + CYData *internal(reinterpret_cast(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(*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(CYCastSymbol(name.data))) - return CYMakeFunctor(context, symbol, entry->value_); + return CYMakeFunctor(context, symbol, entry->value_, &entry->cache_); else return NULL; case '2': diff --git a/Execute.hpp b/Execute.hpp index 6653c9b..922aad4 100644 --- a/Execute.hpp +++ b/Execute.hpp @@ -43,6 +43,7 @@ struct CYBridgeEntry { int name_; const char *value_; + void *cache_; }; extern "C" struct CYBridgeEntry *CYBridgeHash(const char *data, size_t size); diff --git a/Pooling.hpp b/Pooling.hpp index c907662..a182906 100644 --- a/Pooling.hpp +++ b/Pooling.hpp @@ -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(data)->pool_); } - }; template