Re: cvs: php-src /ext/spl config.m4 spl_observer.c

From: Date: Thu, 22 Dec 2005 19:35:29 +0000
Subject: Re: cvs: php-src /ext/spl config.m4 spl_observer.c
References: 1 2 3  Groups: php.cvs 
Request: Send a blank email to php-cvs+get-36153@lists.php.net to get a copy of this message
It's hard for me to believe though that memset() plus copying some values is noticeably slower. For such small structures I doubt it has any impact on the SPL Iterator performance (you're allocating on stack so allocation is not an issue). You can keep it this way, but my $.02 would be to only have the memset()+copy version and nuke the shortcut. It just won't make a difference, and from past experiences I've had, such issues come back and bite you later on :) Andi At 11:23 AM 12/22/2005, Marcus Boerger wrote:
Hello Andi, we would need to enforce structure packing change the type of zend_object_handle in zend_object_value or both. But even if we go that way we are not sure it works, so the only way that would always work is the memset. However setting all structure bytes to zero while on many platforms none must be ste and having to copy the whole think just seems wrong. That means looking for alternatives: 1) Implement a different hash/compare function 2) Do not use zend hashes but something different None of which i want to go. Imo the best option is to stay with current solution and still change zend_object_handle to have the sane size that pointers have: sizeof(zend_object_handle)==sizeof(zend_object_handlers*). That way we would prevent the workaround of initializing a temp copy on nearly any platform (close to 100%). best regards marcus Thursday, December 22, 2005, 8:07:26 PM, you wrote: Are you sure you want to fix it this way? It'll make things less maintainable. I'm sure there's a way to make it one implementation that works everywhere. At 01:36 PM 12/20/2005, Marcus Boerger wrote:
helly           Tue Dec 20 21:36:48 2005 EDT
Modified files:
    /php-src/ext/spl    config.m4 spl_observer.c
Log: - Only apply workaround solution for 64 bit machines when necessary # Actually this can already be necessary on 32 bit machine and
also not be
# necessary on 64 bit machines. It all depends on the compiler settings. http://cvs.php.net/viewcvs.cgi/php-src/ext/spl/config.m4?r1=1.14&r
2=1.15&diff_format=u
Index: php-src/ext/spl/config.m4 diff -u php-src/ext/spl/config.m4:1.14 php-src/ext/spl/config.m4:1.15
--- php-src/ext/spl/config.m4:1.14      Sat Oct  1 15:55:27 2005
+++ php-src/ext/spl/config.m4 Tue Dec 20 21:36:47 2005 @@ -1,4 +1,4 @@ -dnl $Id: config.m4,v 1.14 2005/10/01 15:55:27 helly Exp $ +dnl $Id: config.m4,v 1.15 2005/12/20 21:36:47 helly Exp $ dnl config.m4 for extension SPL PHP_ARG_ENABLE(spl, enable SPL suppport, @@ -8,6 +8,23 @@ if test "$ext_shared" = "yes"; then
     AC_MSG_ERROR(Cannot build SPL as a shared module)
fi + AC_MSG_CHECKING(whether zend_object_value is packed) + AC_TRY_RUN([ +#include "Zend/zend_types.h" +int main(int argc, char **argv) {
+       return ((sizeof(zend_object_handle) +
sizeof(zend_object_handlers*)) == sizeof(zend_object_value)) ? 0 : 1; +} + ], [
+    ac_result=1
+    AC_MSG_RESULT(yes)
+ ],[
+    ac_result=0
+    AC_MSG_RESULT(no)
+ ], [
+    ac_result=0
+    AC_MSG_RESULT(no)
+ ]) + AC_DEFINE(HAVE_PACKED_OBJECT_VALUE, $ac_result, [Whether struct _zend_object_value is packed]) AC_DEFINE(HAVE_SPL, 1, [Whether you want SPL (Standard PHP Library) support]) PHP_NEW_EXTENSION(spl, php_spl.c spl_functions.c spl_engine.c spl_iterators.c spl_array.c spl_directory.c spl_sxe.c spl_exceptions.c spl_observer.c, $ext_shared) fi http://cvs.php.net/viewcvs.cgi/php-src/ext/spl/spl_observer.c?r1=1
.6&r2=1.7&diff_format=u
Index: php-src/ext/spl/spl_observer.c diff -u php-src/ext/spl/spl_observer.c:1.6
php-src/ext/spl/spl_observer.c:1.7
--- php-src/ext/spl/spl_observer.c:1.6 Mon Dec 19 13:53:28 2005
+++ php-src/ext/spl/spl_observer.c      Tue Dec 20 21:36:47 2005
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/ -/* $Id: spl_observer.c,v 1.6 2005/12/19 13:53:28 tony2001 Exp $ */ +/* $Id: spl_observer.c,v 1.7 2005/12/20 21:36:47 helly Exp $ */ #ifdef HAVE_CONFIG_H # include "config.h" @@ -129,17 +129,25 @@ SPL_METHOD(SplObjectStorage, attach) {
        zval *obj;
-       zend_object_value zvalue;
+
        spl_SplObjectStorage *intern =
(spl_SplObjectStorage*)zend_object_store_get_object(getThis() TSRMLS_CC);
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o",
&obj) == FAILURE) {
                return;
        }
-       memset(&zvalue, 0, sizeof(zend_object_value));
-       zvalue.handle = obj->value.obj.handle;
-       zvalue.handlers = obj->value.obj.handlers;
-
-       zend_hash_update(&intern->storage, (char*)&zvalue,
sizeof(zend_object_value), &obj, sizeof(zval*), NULL); + +#if HAVE_PACKED_OBJECT_VALUE
+       zend_hash_update(&intern->storage, (char*)&Z_OBJVAL_P(obj),
sizeof(zend_object_value), &obj, sizeof(zval*), NULL); +#else
+       {
+               zend_object_value zvalue;
+               memset(&zvalue, 0, sizeof(zend_object_value));
+               zvalue.handle = Z_OBJ_HANDLE_P(obj);
+               zvalue.handlers = Z_OBJ_HT_P(obj);
+               zend_hash_update(&intern->storage, (char*)&zvalue,
sizeof(zend_object_value), &obj, sizeof(zval*), NULL);
+       }
+#endif +
        obj->refcount++;
} /* }}} */ @@ -148,17 +156,24 @@ SPL_METHOD(SplObjectStorage, detach) {
        zval *obj;
-       zend_object_value zvalue;
        spl_SplObjectStorage *intern =
(spl_SplObjectStorage*)zend_object_store_get_object(getThis() TSRMLS_CC);
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o",
&obj) == FAILURE) {
                return;
        }
-       memset(&zvalue, 0, sizeof(zend_object_value));
-       zvalue.handle = obj->value.obj.handle;
-       zvalue.handlers = obj->value.obj.handlers;
-
-       zend_hash_del(&intern->storage, (char*)&zvalue,
sizeof(zend_object_value)); + +#if HAVE_PACKED_OBJECT_VALUE
+       zend_hash_del(&intern->storage, (char*)&Z_OBJVAL_P(obj),
sizeof(zend_object_value)); +#else
+       {
+               zend_object_value zvalue;
+               memset(&zvalue, 0, sizeof(zend_object_value));
+               zvalue.handle = Z_OBJ_HANDLE_P(obj);
+               zvalue.handlers = Z_OBJ_HT_P(obj);
+               zend_hash_del(&intern->storage, (char*)&zvalue,
sizeof(zend_object_value));
+       }
+#endif +
        zend_hash_internal_pointer_reset_ex(&intern->storage, 
&intern->pos);
intern->index = 0; } /* }}} */ @@ -168,17 +183,23 @@ SPL_METHOD(SplObjectStorage, contains) {
        zval *obj;
-       zend_object_value zvalue;
        spl_SplObjectStorage *intern =
(spl_SplObjectStorage*)zend_object_store_get_object(getThis() TSRMLS_CC);
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o",
&obj) == FAILURE) {
                return;
        }
-       memset(&zvalue, 0, sizeof(zend_object_value));
-       zvalue.handle = obj->value.obj.handle;
-       zvalue.handlers = obj->value.obj.handlers;
-
-       RETURN_BOOL(zend_hash_exists(&intern->storage,
(char*)&zvalue, sizeof(zend_object_value))); + +#if HAVE_PACKED_OBJECT_VALUE
+       RETURN_BOOL(zend_hash_exists(&intern->storage,
(char*)&Z_OBJVAL_P(obj), sizeof(zend_object_value))); +#else
+       {
+               zend_object_value zvalue;
+               memset(&zvalue, 0, sizeof(zend_object_value));
+               zvalue.handle = Z_OBJ_HANDLE_P(obj);
+               zvalue.handlers = Z_OBJ_HT_P(obj);
+               RETURN_BOOL(zend_hash_exists(&intern->storage,
(char*)&zvalue, sizeof(zend_object_value)));
+       }
+#endif } /* }}} */ /* {{{ proto int SplObjectStorage::count() -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Best regards, Marcus


« previous php.cvs (#36153) next »