Skip to content

Commit 0950081

Browse files
committed
Merge pull request laravel#1204 from bryantebeek/optimisation/str-class
Performance enhancement for Str Class (see pull request laravel#1180)
2 parents fc9b0e1 + 01ba355 commit 0950081

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

laravel/str.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,22 @@ class Str {
99
*/
1010
public static $pluralizer;
1111

12-
/**
13-
* Get the default string encoding for the application.
14-
*
15-
* This method is simply a short-cut to Config::get('application.encoding').
16-
*
17-
* @return string
18-
*/
19-
public static function encoding()
20-
{
21-
return Config::get('application.encoding');
22-
}
12+
/**
13+
* Cache application encoding locally to save expensive calls to Config::get().
14+
*
15+
* @var string
16+
*/
17+
public static $encoding = null;
18+
19+
/**
20+
* Get the appliction.encoding without needing to request it from Config::get() each time.
21+
*
22+
* @return string
23+
*/
24+
protected static function encoding()
25+
{
26+
return static::$encoding ?: static::$encoding = Config::get('application.encoding');
27+
}
2328

2429
/**
2530
* Get the length of a string.

0 commit comments

Comments
 (0)