-
-
Notifications
You must be signed in to change notification settings - Fork 27
Perf: Inline getRootValue in getValue for simple array access #172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -212,6 +212,10 @@ | |
| return $key($array, $default); | ||
| } | ||
|
|
||
| if (is_array($array) && (is_int($key) || is_string($key))) { | ||
| return array_key_exists($key, $array) ? $array[$key] : $default; | ||
samdark marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| if (is_array($key)) { | ||
| if (empty($key)) { | ||
| return $default; | ||
|
|
@@ -754,7 +758,7 @@ | |
| foreach ($array as $element) { | ||
| if (!is_array($element) && !is_object($element)) { | ||
| throw new InvalidArgumentException( | ||
| 'index() can not get value from ' . gettype($element) . | ||
|
Check warning on line 761 in src/ArrayHelper.php
|
||
| '. The $array should be either multidimensional array or an array of objects.' | ||
| ); | ||
| } | ||
|
|
@@ -946,7 +950,7 @@ | |
| * | ||
| * @return bool Whether the array contains the specified key. | ||
| */ | ||
| public static function keyExists(array $array, array|float|int|string $key, bool $caseSensitive = true): bool | ||
|
Check warning on line 953 in src/ArrayHelper.php
|
||
| { | ||
| if (is_array($key)) { | ||
| if (empty($key)) { | ||
|
|
@@ -1025,7 +1029,7 @@ | |
| public static function pathExists( | ||
| array $array, | ||
| array|float|int|string $path, | ||
| bool $caseSensitive = true, | ||
|
Check warning on line 1032 in src/ArrayHelper.php
|
||
| string $delimiter = '.' | ||
| ): bool { | ||
| return self::keyExists($array, self::parseMixedPath($path, $delimiter), $caseSensitive); | ||
|
|
@@ -1054,7 +1058,7 @@ | |
| $data = iterator_to_array($data); | ||
| } | ||
|
|
||
| $encoding ??= ini_get('default_charset') ?: 'UTF-8'; | ||
|
Check warning on line 1061 in src/ArrayHelper.php
|
||
| $flags = ENT_QUOTES | ENT_SUBSTITUTE; | ||
|
|
||
| return $valuesOnly | ||
|
|
@@ -1358,7 +1362,7 @@ | |
| $numNestedKeys = count($keys) - 1; | ||
| foreach ($keys as $i => $key) { | ||
| if (!is_array($excludeNode) || !array_key_exists($key, $excludeNode)) { | ||
| continue 2; // Jump to the next filter. | ||
|
Check warning on line 1365 in src/ArrayHelper.php
|
||
| } | ||
|
|
||
| if ($i < $numNestedKeys) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.