Daniel Werner has submitted this change and it was merged.
Change subject: Cache the hash on locations where it makes sense, as per
danielks suggestion
......................................................................
Cache the hash on locations where it makes sense, as per danielks suggestion
Change-Id: Ide4546816ea0098151f4a1ac9175a3eaa142d682
---
M includes/Ask/Language/Description/DescriptionCollection.php
M includes/Ask/Language/Description/SomeProperty.php
2 files changed, 43 insertions(+), 17 deletions(-)
Approvals:
Daniel Werner: Verified; Looks good to me, approved
jenkins-bot: Checked
diff --git a/includes/Ask/Language/Description/DescriptionCollection.php
b/includes/Ask/Language/Description/DescriptionCollection.php
index ea5142f..58c21c6 100644
--- a/includes/Ask/Language/Description/DescriptionCollection.php
+++ b/includes/Ask/Language/Description/DescriptionCollection.php
@@ -37,7 +37,16 @@
*
* @var Description[]
*/
- protected $descriptions;
+ private $descriptions;
+
+ /**
+ * Cache for the hash.
+ *
+ * @since 0.1
+ *
+ * @var string|null
+ */
+ private $hash;
/**
* Constructor.
@@ -166,20 +175,24 @@
* @return string
*/
public function getHash() {
- $this->sortCollection( $this->descriptions );
+ if ( $this->hash === null ) {
+ $this->sortCollection( $this->descriptions );
- return sha1(
- $this->getType() .
- implode(
- '|',
- array_map(
- function( Hashable $hashable ) {
- return $hashable->getHash();
- },
- $this->descriptions
+ $this->hash = sha1(
+ $this->getType() .
+ implode(
+ '|',
+ array_map(
+ function( Hashable $hashable ) {
+ return
$hashable->getHash();
+ },
+ $this->descriptions
+ )
)
- )
- );
+ );
+ }
+
+ return $this->hash;
}
/**
@@ -189,7 +202,7 @@
*
* @param Hashable[] $array
*/
- protected function sortCollection( array &$array ) {
+ final protected function sortCollection( array &$array ) {
usort(
$array,
function ( Hashable $a, Hashable $b ) {
diff --git a/includes/Ask/Language/Description/SomeProperty.php
b/includes/Ask/Language/Description/SomeProperty.php
index 07d39cf..d851776 100644
--- a/includes/Ask/Language/Description/SomeProperty.php
+++ b/includes/Ask/Language/Description/SomeProperty.php
@@ -44,14 +44,23 @@
*
* @var PropertyValue
*/
- protected $property;
+ private $property;
/**
* @since 0.1
*
* @var Description
*/
- protected $description;
+ private $description;
+
+ /**
+ * Cache for the hash.
+ *
+ * @since 0.1
+ *
+ * @var string|null
+ */
+ private $hash;
/**
* Constructor.
@@ -158,7 +167,11 @@
* @return string
*/
public function getHash() {
- return sha1( $this->getType() . $this->property->getHash() .
$this->description->getHash() );
+ if ( $this->hash === null ) {
+ $this->hash = sha1( $this->getType() .
$this->property->getHash() . $this->description->getHash() );
+ }
+
+ return $this->hash;
}
}
--
To view, visit https://gerrit.wikimedia.org/r/49945
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ide4546816ea0098151f4a1ac9175a3eaa142d682
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Ask
Gerrit-Branch: master
Gerrit-Owner: Jeroen De Dauw <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Daniel Werner <[email protected]>
Gerrit-Reviewer: John Erling Blad <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits