]> git.saurik.com Git - apple/objc4.git/blobdiff - runtime/objc-opt.mm
objc4-680.tar.gz
[apple/objc4.git] / runtime / objc-opt.mm
index e14e5b358f340c7683982cb751e071820a578327..cc168e12d33d62c58e7e453b1f515665d45f1f8d 100644 (file)
@@ -39,11 +39,21 @@ bool isPreoptimized(void)
     return false;
 }
 
+bool header_info::isPreoptimized() const
+{
+    return false;
+}
+
 objc_selopt_t *preoptimizedSelectors(void) 
 {
     return nil;
 }
 
+Protocol *getPreoptimizedProtocol(const char *name)
+{
+    return nil;
+}
+
 Class getPreoptimizedClass(const char *name)
 {
     return nil;
@@ -77,6 +87,8 @@ void preopt_init(void)
 
 #include <objc-shared-cache.h>
 
+using objc_opt::objc_stringhash_offset_t;
+using objc_opt::objc_protocolopt_t;
 using objc_opt::objc_clsopt_t;
 using objc_opt::objc_headeropt_t;
 using objc_opt::objc_opt_t;
@@ -97,11 +109,37 @@ bool isPreoptimized(void)
     return preoptimized;
 }
 
+
+/***********************************************************************
+* Return YES if this image's dyld shared cache optimizations are valid.
+**********************************************************************/
+bool header_info::isPreoptimized() const
+{
+    // preoptimization disabled for some reason
+    if (!preoptimized) return NO;
+
+    // image not from shared cache, or not fixed inside shared cache
+    if (!_objcHeaderOptimizedByDyld(this)) return NO;
+
+    return YES;
+}
+
+
 objc_selopt_t *preoptimizedSelectors(void) 
 {
     return opt ? opt->selopt() : nil;
 }
 
+
+Protocol *getPreoptimizedProtocol(const char *name)
+{
+    objc_protocolopt_t *protocols = opt ? opt->protocolopt() : nil;
+    if (!protocols) return nil;
+
+    return (Protocol *)protocols->getProtocol(name);
+}
+
+
 Class getPreoptimizedClass(const char *name)
 {
     objc_clsopt_t *classes = opt ? opt->clsopt() : nil;
@@ -110,7 +148,7 @@ Class getPreoptimizedClass(const char *name)
     void *cls;
     void *hi;
     uint32_t count = classes->getClassAndHeader(name, cls, hi);
-    if (count == 1  &&  ((header_info *)hi)->loaded) {
+    if (count == 1  &&  ((header_info *)hi)->isLoaded()) {
         // exactly one matching class, and its image is loaded
         return (Class)cls;
     } 
@@ -120,7 +158,7 @@ Class getPreoptimizedClass(const char *name)
         void *hilist[count];
         classes->getClassesAndHeaders(name, clslist, hilist);
         for (uint32_t i = 0; i < count; i++) {
-            if (((header_info *)hilist[i])->loaded) {
+            if (((header_info *)hilist[i])->isLoaded()) {
                 return (Class)clslist[i];
             }
         }
@@ -143,8 +181,8 @@ Class* copyPreoptimizedClasses(const char *name, int *outCount)
     uint32_t count = classes->getClassAndHeader(name, cls, hi);
     if (count == 0) return nil;
 
-    Class *result = (Class *)_calloc_internal(count, sizeof(Class));
-    if (count == 1  &&  ((header_info *)hi)->loaded) {
+    Class *result = (Class *)calloc(count, sizeof(Class));
+    if (count == 1  &&  ((header_info *)hi)->isLoaded()) {
         // exactly one matching class, and its image is loaded
         result[(*outCount)++] = (Class)cls;
         return result;
@@ -155,7 +193,7 @@ Class* copyPreoptimizedClasses(const char *name, int *outCount)
         void *hilist[count];
         classes->getClassesAndHeaders(name, clslist, hilist);
         for (uint32_t i = 0; i < count; i++) {
-            if (((header_info *)hilist[i])->loaded) {
+            if (((header_info *)hilist[i])->isLoaded()) {
                 result[(*outCount)++] = (Class)clslist[i];
             }
         }
@@ -192,7 +230,7 @@ struct objc_headeropt_t {
             else start = i+1;
         }
 
-#if !NDEBUG
+#if DEBUG
         for (uint32_t i = 0; i < count; i++) {
             header_info *hi = headers+i;
             if (mhdr == hi->mhdr) {