Skip to content

Commit 0b69f50

Browse files
committed
Merge pull request #451 from wmde/slPerf
Avoid looping Statement arrays twice
2 parents 2c6435d + 1c1793c commit 0b69f50

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

src/Statement/StatementList.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,15 @@ public function getWithUniqueMainSnaks() {
130130
* @return StatementList
131131
*/
132132
public function getWithPropertyId( PropertyId $id ) {
133-
$statements = array();
133+
$statementList = new self();
134134

135135
foreach ( $this->statements as $statement ) {
136136
if ( $statement->getPropertyId()->equals( $id ) ) {
137-
$statements[] = $statement;
137+
$statementList->addStatement( $statement );
138138
}
139139
}
140140

141-
return new self( $statements );
141+
return $statementList;
142142
}
143143

144144
/**
@@ -150,15 +150,15 @@ public function getWithPropertyId( PropertyId $id ) {
150150
*/
151151
public function getWithRank( $acceptableRanks ) {
152152
$acceptableRanks = array_flip( (array)$acceptableRanks );
153-
$statements = array();
153+
$statementList = new self();
154154

155155
foreach ( $this->statements as $statement ) {
156156
if ( array_key_exists( $statement->getRank(), $acceptableRanks ) ) {
157-
$statements[] = $statement;
157+
$statementList->addStatement( $statement );
158158
}
159159
}
160160

161-
return new self( $statements );
161+
return $statementList;
162162
}
163163

164164
/**

0 commit comments

Comments
 (0)