Two patches for more Performance
--------------------------------

                 Key: THRIFT-1521
                 URL: https://issues.apache.org/jira/browse/THRIFT-1521
             Project: Thrift
          Issue Type: Improvement
          Components: PHP - Library
    Affects Versions: 0.8, 0.7, 0.6.1, 0.9, 1.0, 1.1
            Reporter: D. Edler
         Attachments: patch.diff

There are two double Function calls to strlen, which can easily prevented.


Index: trunk/lib/php/src/transport/TTransport.php
===================================================================
--- trunk/lib/php/src/transport/TTransport.php  (revision 1292723)
+++ trunk/lib/php/src/transport/TTransport.php  (working copy)
@@ -81,7 +81,7 @@
   public function readAll($len) {
     // return $this->read($len);
 
-    $data = '';
+    $data = $this->read($len - $got);
     $got = 0;
     while (($got = TStringFuncFactory::create()->strlen($data)) < $len) {
       $data .= $this->read($len - $got);
Index: trunk/lib/php/src/transport/TMemoryBuffer.php
===================================================================
--- trunk/lib/php/src/transport/TMemoryBuffer.php       (revision 1292723)
+++ trunk/lib/php/src/transport/TMemoryBuffer.php       (working copy)
@@ -54,13 +54,15 @@
   }
 
   public function read($len) {
-    if (TStringFuncFactory::create()->strlen($this->buf_) === 0) {
+    $bufLength = TStringFuncFactory::create()->strlen($this->buf_);
+
+    if ($bufLength === 0) {
       throw new TTransportException('TMemoryBuffer: Could not read ' .
                                     $len . ' bytes from buffer.',
                                     TTransportException::UNKNOWN);
     }
 
-    if (TStringFuncFactory::create()->strlen($this->buf_) <= $len) {
+    if ($bufLength <= $len) {
       $ret = $this->buf_;
       $this->buf_ = '';
       return $ret;

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to