Skip to content

Commit 24f2fb6

Browse files
Optimize EntityId::isForeign()
When this method was first introduced, getRepositoryName() would split the serialization each time it was called, and using strpos() in isForeign() was an optimization to avoid that cost. However, since #769 (commit eb66561), the serialization is only split once in the constructor, so checking strpos each time instead of deferring to the already populated $repositoryName is probably slightly more expensive. As a very minor optimization, we directly access $this->repositoryName instead of calling getRepositoryName(). Subclasses that for some reason override getRepositoryName() to do something different must override isForeign() as well.
1 parent f68fa92 commit 24f2fb6

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

RELEASE-NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
* `TermList` now throws `InvalidArgumentException` when given non-iterable rather than failing silently
66
* `SiteLinkList` now throws `InvalidArgumentException` when given non-iterable rather than failing silently
7+
* Slightly optimized `EntityId::isForeign()` by using `$this->repositoryName` instead of `$this->serialization`
78

89
## Version 9.1.0 (2019-01-24)
910

src/Entity/EntityId.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,14 @@ public function getLocalPart() {
164164
}
165165

166166
/**
167-
* Returns true iff EntityId::getRepoName returns a non-empty string.
167+
* Returns true iff EntityId::getRepositoryName returns a non-empty string.
168168
*
169169
* @since 6.2
170170
*
171171
* @return bool
172172
*/
173173
public function isForeign() {
174-
// not actually using EntityId::getRepoName for performance reasons
175-
return strpos( $this->serialization, ':' ) > 0;
174+
return $this->repositoryName !== '';
176175
}
177176

178177
/**

0 commit comments

Comments
 (0)