Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Reduced the #calls of rawurlencode() using a cache mechanism #3045

Closed
wants to merge 1 commit into from

3 participants

Enrico Zimuel Matthew Weier O'Phinney Maks3w
Enrico Zimuel
Owner

This patch reduce the #calls of the rawurlencode() for the Zend\Mvc\Router\Http\Segment->encode(). In the zf2-tutorial application this reduce the rawurlencode() calls from 181 to 48 with a reduction of 1% of the total response time.

Maks3w Maks3w commented on the diff
library/Zend/Mvc/Router/Http/Segment.php
@@ -25,6 +25,11 @@
class Segment implements RouteInterface
{
/**
+ * @var array Cache for the encode output
+ */
+ private static $__cacheEncode = array();
Maks3w Collaborator
Maks3w added a note

var name should not start with underscores

Matthew Weier O'Phinney Owner
Maks3w Collaborator
Maks3w added a note

For me the private visibility is enough since forbid "unauthorized" modifications in extended classes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Matthew Weier O'Phinney weierophinney referenced this pull request from a commit
Matthew Weier O'Phinney weierophinney [#3045] Rename private variable
- Remove double underscore prefix
fd07e64
Matthew Weier O'Phinney

Renamed variable on merge, per note from @Maks3w

Deleted user Unknown referenced this pull request from a commit
Matthew Weier O'Phinney weierophinney [#3045] Rename private variable
- Remove double underscore prefix
b3b6b45
Deleted user Unknown referenced this pull request from a commit
Matthew Weier O'Phinney weierophinney Merge branch 'hotfix/3045'
Close #3045
aa1004e
Deleted user Unknown referenced this pull request from a commit
Matthew Weier O'Phinney weierophinney Merge branch 'hotfix/3045' into develop
Forward port #3045
26ba811
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 21, 2012
  1. Enrico Zimuel
This page is out of date. Refresh to see the latest.
Showing with 10 additions and 3 deletions.
  1. +10 −3 library/Zend/Mvc/Router/Http/Segment.php
13 library/Zend/Mvc/Router/Http/Segment.php
View
@@ -25,6 +25,11 @@
class Segment implements RouteInterface
{
/**
+ * @var array Cache for the encode output
+ */
+ private static $__cacheEncode = array();
Maks3w Collaborator
Maks3w added a note

var name should not start with underscores

Matthew Weier O'Phinney Owner
Maks3w Collaborator
Maks3w added a note

For me the private visibility is enough since forbid "unauthorized" modifications in extended classes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+
+ /**
* Map of allowed special chars in path segments.
*
* http://tools.ietf.org/html/rfc3986#appendix-A
@@ -408,9 +413,11 @@ public function getAssembledParams()
*/
private function encode($value)
{
- $encoded = rawurlencode($value);
- $encoded = strtr($encoded, static::$urlencodeCorrectionMap);
- return $encoded;
+ if (!isset(static::$__cacheEncode[$value])) {
+ static::$__cacheEncode[$value] = rawurlencode($value);
+ static::$__cacheEncode[$value] = strtr(static::$__cacheEncode[$value], static::$urlencodeCorrectionMap);
+ }
+ return static::$__cacheEncode[$value];
}
/**
Something went wrong with that request. Please try again.