Optimization: skip call to 'has' method when possible

This commit is contained in:
Pekka Laiho 2020-12-03 09:58:58 +07:00
parent 330fda6715
commit d6127e6821
4 changed files with 4 additions and 4 deletions

View File

@ -23,7 +23,7 @@ class Env extends Hash
public function get(string $key)
{
if ($this->has($key)) {
if (array_key_exists($key, $this->data)) {
return $this->data[$key];
} elseif ($this->parent) {
return $this->parent->get($key);

View File

@ -5,7 +5,7 @@ class Hash extends Collection
{
public function get(string $key)
{
if ($this->has($key)) {
if (array_key_exists($key, $this->data)) {
return $this->data[$key];
}

View File

@ -5,7 +5,7 @@ class MList extends Seq
{
public function get(int $index)
{
if ($this->has($index)) {
if (array_key_exists($index, $this->data)) {
return $this->data[$index];
}

View File

@ -5,7 +5,7 @@ class Vector extends Seq
{
public function get(int $index)
{
if ($this->has($index)) {
if (array_key_exists($index, $this->data)) {
return $this->data[$index];
}