1. Ronald Oussoren
  2. pyobjc-3.0-unstable

Commits

Ronald Oussoren  committed 948ea04

Some small tweaks

* Re-enable -O4 (but still for PyObjC_DEBUG to on)

* The static typecode strings in method-signature can be shared
between normal values, ptr-to-value and in-ptr-to-value for slightly
reduced memory usage.

* Mark the condiction in PyObjC_Assert as unlikely

  • Participants
  • Parent commits 88df8e5
  • Branches core-cleanup

Comments (0)

Files changed (3)

File pyobjc-core/Modules/objc/method-signature.m

View file
  • Ignore whitespace
 static PyObjCMethodSignature* new_methodsignature(const char*);
 
 /*
- * TODO:
- * - If this works out: als create templates for byref in/out/inout types
- * - Compile metadata into partial MethodSignature struct in "PyObjC_registerMetaData"
- *   (set 'tmpl' bit in all entries). Be careful to not cause memory corruption when
- *   existing metadata is replaced (but leak memory instead)
+ * Define static strings and struct _PyObjC_ArgDescr values that
+ * are used to share compiled metadata for basic types. These
+ * shared "template" structures reduce the amount of memory used
+ * by metadata structures, at a slight cost in static read-only
+ * data and slightly more complicated code.
  */
-
-#define TC(VAL)  [VAL] = { VAL, 0 }
-static const char _static_typecodes[256][2] = {
-    TC(_C_VOID),
-    TC(_C_ID),
-    TC(_C_CLASS),
-    TC(_C_SEL),
-    TC(_C_BOOL),    TC(_C_NSBOOL),
-    TC(_C_CHR),     TC(_C_UCHR),
-    TC(_C_SHT),     TC(_C_USHT),
-    TC(_C_INT),     TC(_C_UINT),
-    TC(_C_LNG),     TC(_C_ULNG),
-    TC(_C_LNG_LNG), TC(_C_ULNG_LNG),
-    TC(_C_FLT),     TC(_C_DBL),
-    TC(_C_CHAR_AS_TEXT),
-    TC(_C_CHAR_AS_INT),
-    TC(_C_UNICHAR),
-};
-#undef TC
-
-#define TC(VAL)  [VAL] = { _C_PTR, VAL, 0 }
-static const char _ptr_typecodes[256][3] = {
-    TC(_C_VOID),
-    TC(_C_ID),
-    TC(_C_CLASS),
-    TC(_C_SEL),
-    TC(_C_BOOL),    TC(_C_NSBOOL),
-    TC(_C_CHR),     TC(_C_UCHR),
-    TC(_C_SHT),     TC(_C_USHT),
-    TC(_C_INT),     TC(_C_UINT),
-    TC(_C_LNG),     TC(_C_ULNG),
-    TC(_C_LNG_LNG), TC(_C_ULNG_LNG),
-    TC(_C_FLT),     TC(_C_DBL),
-    TC(_C_CHAR_AS_TEXT),
-    TC(_C_CHAR_AS_INT),
-    TC(_C_UNICHAR),
-};
-#undef TC
-
 #define TC(VAL)  [VAL] = { _C_IN, _C_PTR, VAL, 0 }
 static const char _ptr_in_typecodes[256][4] = {
     TC(_C_VOID),
 
 static const char _block_typecode[] = { _C_ID, _C_UNDEF, 0 };
 
-#define TC(VAL) [VAL] = { .type = _static_typecodes[VAL], .tmpl = 1, .allowNULL = 1 }
+#define TC(VAL) [VAL] = { .type = _ptr_in_typecodes[VAL]+2, .tmpl = 1, .allowNULL = 1 }
 static const struct _PyObjC_ArgDescr descr_templates[256] = {
     TC(_C_VOID),
     TC(_C_ID),
 };
 #undef TC
 
-#define TC(VAL) [VAL] = { .type = _ptr_typecodes[VAL], .tmpl = 1, .allowNULL = 1 }
+#define TC(VAL) [VAL] = { .type = _ptr_in_typecodes[VAL]+1, .tmpl = 1, .allowNULL = 1 }
 static const struct _PyObjC_ArgDescr ptr_templates[256] = {
     TC(_C_VOID),
     TC(_C_ID),

File pyobjc-core/Modules/objc/pyobjc-assert.h

View file
  • Ignore whitespace
 
 #define PyObjC_Assert(expr, retval) 				\
     do { 							\
-    if (!(expr)) { PyObjCErr_InternalErrorMesg(			\
+    if (unlikely(!(expr))) { PyObjCErr_InternalErrorMesg(			\
             "assertion failed: " #expr); return (retval); } 	\
     } while (0)
 #else

File pyobjc-core/setup.py

View file
  • Ignore whitespace
     cfg_vars = get_config_vars()
     for k in cfg_vars:
         if isinstance(cfg_vars[k], str) and '-O2' in cfg_vars[k]:
-            cfg_vars[k] = cfg_vars[k].replace('-O2', '-O1')
+            cfg_vars[k] = cfg_vars[k].replace('-O2', '-O4')
         elif isinstance(cfg_vars[k], str) and '-O3' in cfg_vars[k]:
-            cfg_vars[k] = cfg_vars[k].replace('-O3', '-O1')
+            cfg_vars[k] = cfg_vars[k].replace('-O3', '-O4')
 
 OBJC_LDFLAGS.append("-fvisibility=hidden")