Przeglądaj źródła

strlen optimization

walkor 5 lat temu
rodzic
commit
0fd2e4601d
2 zmienionych plików z 4 dodań i 4 usunięć
  1. 1 1
      Protocols/Http.php
  2. 3 3
      Protocols/Http/Request.php

+ 1 - 1
Protocols/Http.php

@@ -148,7 +148,7 @@ class Http
      */
     public static function decode($recv_buffer, TcpConnection $connection)
     {
-        $cacheable = static::$_enableCache && \strlen($recv_buffer) < 512;
+        $cacheable = static::$_enableCache && !isset($recv_buffer[512]);
         if (true === $cacheable && isset(static::$_cache[$recv_buffer])) {
             $request = static::$_cache[$recv_buffer];
             $request->connection = $connection;

+ 3 - 3
Protocols/Http/Request.php

@@ -392,7 +392,7 @@ class Request
         $this->_data['headers'] = array();
         $raw_head = $this->rawHead();
         $head_buffer = \substr($raw_head, \strpos($raw_head, "\r\n") + 2);
-        $cacheable = static::$_enableCache && \strlen($head_buffer) < 2048;
+        $cacheable = static::$_enableCache && !isset($head_buffer[2048]);
         if ($cacheable && isset(static::$_headerCache[$head_buffer])) {
             $this->_data['headers'] = static::$_headerCache[$head_buffer];
             return;
@@ -426,7 +426,7 @@ class Request
         if ($query_string === '') {
             return;
         }
-        $cacheable = static::$_enableCache && \strlen($query_string) < 1024;
+        $cacheable = static::$_enableCache && !isset($query_string[1024]);
         if ($cacheable && isset(static::$_getCache[$query_string])) {
             $this->_data['get'] = static::$_getCache[$query_string];
             return;
@@ -452,7 +452,7 @@ class Request
         if ($body_buffer === '') {
             return;
         }
-        $cacheable = static::$_enableCache && \strlen($body_buffer) < 1024;
+        $cacheable = static::$_enableCache && !isset($body_buffer[1024]);
         if ($cacheable && isset(static::$_postCache[$body_buffer])) {
             $this->_data['post'] = static::$_postCache[$body_buffer];
             return;