]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Optimize IS_INSTANCE.
authorBruno Haible <bruno@clisp.org>
Mon, 27 Nov 2006 12:38:51 +0000 (12:38 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:14:24 +0000 (12:14 +0200)
gnulib-local/ChangeLog
gnulib-local/build-aux/moopp
gnulib-local/lib/moo.h

index 06ff47d655e6bef5bc80fdcbfc50936ee443efd7..d16273b1f283d883c3fe204f124a19c1e73f39a2 100644 (file)
@@ -1,3 +1,11 @@
+2006-11-26  Bruno Haible  <bruno@clisp.org>
+
+       Optimize IS_INSTANCE.
+       * build-aux/moopp: Emit also a classname_SUPERCLASSES_LENGTH macro.
+       * lib/moo.h (IS_INSTANCE): Use the value of this macro, known at
+       compile time.
+       (IS_INSTANCE_PRIVATE): Remove macro.
+
 2006-11-26  Bruno Haible  <bruno@clisp.org>
 
        * lib/moo.h (IS_INSTANCE): Fix reference to vtable.
index 4fa4455701e604bbe6c60ee9f84eabc9b1868cdb..473fae613860aae8e7d118debb8f8efca3d3fe82 100755 (executable)
@@ -453,6 +453,11 @@ func_start_creation "$newfile"
     superclasses_array_initializer="NULL"
   fi
   echo "#define ${main_classname}_SUPERCLASSES &${main_classname}_typeinfo, ${superclasses_array_initializer}"
+  if test -n "${main_superclassname}"; then
+    echo "#define ${main_classname}_SUPERCLASSES_LENGTH (1 + ${main_superclassname}_SUPERCLASSES_LENGTH)"
+  else
+    echo "#define ${main_classname}_SUPERCLASSES_LENGTH (1 + 1)"
+  fi
   echo
   echo "extern const struct ${main_classname}_implementation ${main_classname}_vtable;"
   echo
index 75e2adad6e261384d7e392a3d06ea90be2e9e028..95d09cb03877aec8c58fa624fb3f54ce44664a88 100644 (file)
        each being a typeinfo_t instance.
      - A declaration of 'ROOTFOO_SUPERCLASSES' or 'SUBCLASS_SUPERCLASSES',
        respectively, each being an initializer for an array of typeinfo_t.
+     - A declaration of 'ROOTFOO_SUPERCLASSES_LENGTH' or
+       'SUBCLASS_SUPERCLASSES_LENGTH', respectively, each denoting the length
+       of that initializer.
      - A declaration of 'rootfoo_vtable' or 'subclass_vtable', respectively,
        being an instance of 'struct rootfoo_implementation' or
        'struct subclass_implementation', respectively.
@@ -222,24 +225,14 @@ typedef struct
 } typeinfo_t;
 
 /* IS_INSTANCE (OBJ, ROOTCLASSNAME, CLASSNAME)
-   IS_INSTANCE_PRIVATE (OBJ, ROOTCLASSNAME, CLASSNAME)
-   test whether an object is instance of a given class, given as lower case
-   class name.
-   IS_INSTANCE can be used anywhere; IS_INSTANCE_PRIVATE can only be used in
-   the file that implements CLASSNAME but is better optimized.  */
+   tests whether an object is instance of a given class, given as lower case
+   class name.  */
 #define IS_INSTANCE(obj,rootclassname,classname) \
   (((const struct rootclassname##_representation_header *)(const struct any_##rootclassname##_representation *)(obj))->vtable->superclasses_length \
-   >= classname##_vtable.superclasses_length \
+   >= classname##_SUPERCLASSES_LENGTH \
    && ((const struct rootclassname##_representation_header *)(const struct any_##rootclassname##_representation *)(obj))->vtable->superclasses \
       [((const struct rootclassname##_representation_header *)(const struct any_##rootclassname##_representation *)(obj))->vtable->superclasses_length \
-       - classname##_vtable.superclasses_length] \
-      == & classname##_typeinfo)
-#define IS_INSTANCE_PRIVATE(obj,rootclassname,classname) \
-  (((const struct rootclassname##_representation_header *)(const struct any_##rootclassname##_representation *)(obj))->vtable->superclasses_length \
-   >= sizeof (classname##_superclasses) / sizeof (classname##_superclasses[0]) \
-   && ((const struct rootclassname##_representation_header *)(const struct any_##rootclassname##_representation *)(obj))->vtable->superclasses \
-      [((const struct rootclassname##_representation_header *)(const struct any_##rootclassname##_representation *)(obj))->vtable->superclasses_length \
-       - sizeof (classname##_superclasses) / sizeof (classname##_superclasses[0])] \
+       - classname##_SUPERCLASSES_LENGTH] \
       == & classname##_typeinfo)
 /* This instance test consists of two comparisons.  One could even optimize
    this to a single comparison, by limiting the inheritance depth to a fixed
@@ -247,9 +240,9 @@ typedef struct
    need to be stored in reverse order, from the root down to the class itself,
    and be filled up with NULLs so that the array has length 10.  The instance
    test would look like this:
-     #define IS_INSTANCE_PRIVATE(obj,rootclassname,classname) \
+     #define IS_INSTANCE(obj,rootclassname,classname) \
        (((const struct rootclassname##_representation_header *)(const struct any_##rootclassname##_representation *)(obj))->vtable->superclasses \
-        [classname##_superclasses_length - 1] \
+        [classname##_SUPERCLASSES_LENGTH - 1] \
         == & classname##_typeinfo)
    but the classname##_superclasses_length would no longer be available as a
    simple sizeof expression.  */