From: Bruno Haible Date: Mon, 27 Nov 2006 12:38:51 +0000 (+0000) Subject: Optimize IS_INSTANCE. X-Git-Tag: v0.17~635 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1b8f928378053cd0d983f062f753c4972fbcff15;p=thirdparty%2Fgettext.git Optimize IS_INSTANCE. --- diff --git a/gnulib-local/ChangeLog b/gnulib-local/ChangeLog index 06ff47d65..d16273b1f 100644 --- a/gnulib-local/ChangeLog +++ b/gnulib-local/ChangeLog @@ -1,3 +1,11 @@ +2006-11-26 Bruno Haible + + 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 * lib/moo.h (IS_INSTANCE): Fix reference to vtable. diff --git a/gnulib-local/build-aux/moopp b/gnulib-local/build-aux/moopp index 4fa445570..473fae613 100755 --- a/gnulib-local/build-aux/moopp +++ b/gnulib-local/build-aux/moopp @@ -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 diff --git a/gnulib-local/lib/moo.h b/gnulib-local/lib/moo.h index 75e2adad6..95d09cb03 100644 --- a/gnulib-local/lib/moo.h +++ b/gnulib-local/lib/moo.h @@ -157,6 +157,9 @@ 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. */