Browse Source

ZF-10487: AMF3 serialization performance

- Applied patch Amf.perform.ref-writeString-1.10.5.patch
- Also applied spl_object_hash() improvements as suggested in comments

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@23682 44c647ce-9c0f-0410-b52a-842ac1e357ba
matthew 15 years ago
parent
commit
9a5105120c
1 changed files with 10 additions and 5 deletions
  1. 10 5
      library/Zend/Amf/Parse/Amf3/Serializer.php

+ 10 - 5
library/Zend/Amf/Parse/Amf3/Serializer.php

@@ -236,9 +236,11 @@ class Zend_Amf_Parse_Amf3_Serializer extends Zend_Amf_Parse_Serializer
             return $this;
         }
 
-        $ref = array_search($string, $this->_referenceStrings, true);
-        if($ref === false){
-            $this->_referenceStrings[] = $string;
+        $ref = array_key_exists($string, $this->_referenceStrings) 
+             ? $this->_referenceStrings[$string] 
+             : false;
+        if ($ref === false){
+            $this->_referenceStrings[$string] = count($this->_referenceStrings);
             $this->writeBinaryString($string);
         } else {
             $ref <<= 1;
@@ -386,7 +388,10 @@ class Zend_Amf_Parse_Amf3_Serializer extends Zend_Amf_Parse_Serializer
             $object = &$objectByVal;
         }
 
-        $ref = array_search($object, $this->_referenceObjects,true);
+        $hash = spl_object_hash($object);
+        $ref = array_key_exists($hash, $this->_referenceObjects) 
+             ? $this->_referenceObjects[$hash] 
+             : false;
 
         // quickly handle object references
         if ($ref !== false){
@@ -394,7 +399,7 @@ class Zend_Amf_Parse_Amf3_Serializer extends Zend_Amf_Parse_Serializer
             $this->writeInteger($ref);
             return true;
         }
-        $this->_referenceObjects[] = $object;
+        $this->_referenceObjects[$hash] = count($this->_referenceObjects);
         return false;
     }