Skip to content

Commit

Permalink
Minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
aimeos committed Dec 6, 2024
1 parent 73016e5 commit 8cb2312
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/Map.php
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ public function col( ?string $valuecol = null, ?string $indexcol = null ) : self

foreach( $this->list() as $item )
{
$v = $valuecol ? $this->val( $item, $vparts ) : $item;
$v = $valuecol !== null ? $this->val( $item, $vparts ) : $item;

if( $indexcol !== null && ( $key = $this->val( $item, $iparts ) ) !== null ) {
$list[(string) $key] = $v;
Expand Down Expand Up @@ -1827,7 +1827,7 @@ public function get( $key, $default = null )
*/
public function getIterator() : \ArrayIterator
{
return new \ArrayIterator( $this->list = $this->array( $this->list ) );
return new \ArrayIterator( $this->list() );
}


Expand Down Expand Up @@ -2569,17 +2569,13 @@ public function intersectAssoc( iterable $elements, ?callable $callback = null )
*/
public function intersectKeys( iterable $elements, ?callable $callback = null ) : self
{
$list = $this->list();
$elements = $this->array( $elements );

if( $callback ) {
return new static( array_intersect_ukey( $list, $elements, $callback ) );
return new static( array_intersect_ukey( $this->list(), $elements, $callback ) );
}

// using array_intersect_key() is 1.6x slower
return ( new static( $list ) )
->remove( array_keys( array_diff_key( $list, $elements ) ) )
->remove( array_keys( array_diff_key( $elements, $list ) ) );
return new static( array_intersect_key( $this->list(), $elements ) );
}


Expand Down Expand Up @@ -3391,7 +3387,7 @@ public function order( iterable $keys ) : self
$result = [];
$list = $this->list();

foreach( $this->array( $keys ) as $key ) {
foreach( $keys as $key ) {
$result[$key] = $list[$key] ?? null;
}

Expand Down Expand Up @@ -3605,7 +3601,6 @@ public function pos( $value ) : ?int
}
}


if( ( $key = array_search( $value, $list, true ) ) !== false
&& ( $pos = array_search( $key, array_keys( $list ), true ) ) !== false
) {
Expand Down

0 comments on commit 8cb2312

Please sign in to comment.