Krinkle has uploaded a new change for review.
https://gerrit.wikimedia.org/r/247509
Change subject: CacheLRU: Simplify >0 assertion and remove verbose inline
comment
......................................................................
CacheLRU: Simplify >0 assertion and remove verbose inline comment
* Consistently refer to above zero as '> 0', not ">= 1" or "not <= 0".
* Remove superfluous comment that say what ping() does.
Change-Id: I25d276faa555e02feb99e656eb9cb7071f8205c0
---
M includes/libs/MapCacheLRU.php
M includes/libs/ProcessCacheLRU.php
2 files changed, 11 insertions(+), 14 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/09/247509/1
diff --git a/includes/libs/MapCacheLRU.php b/includes/libs/MapCacheLRU.php
index a0230be..a49eb01 100644
--- a/includes/libs/MapCacheLRU.php
+++ b/includes/libs/MapCacheLRU.php
@@ -39,11 +39,11 @@
/**
* @param int $maxKeys Maximum number of entries allowed (min 1).
- * @throws Exception When $maxCacheKeys is not an int or =< 0.
+ * @throws Exception When $maxCacheKeys is not an int or not above zero.
*/
public function __construct( $maxKeys ) {
Assert::parameterType( 'integer', $maxKeys, '$maxKeys' );
- Assert::parameter( $maxKeys >= 1, '$maxKeys', 'must be >= 1' );
+ Assert::parameter( $maxKeys > 0, '$maxKeys', 'must be above
zero' );
$this->maxCacheKeys = $maxKeys;
}
@@ -59,7 +59,7 @@
*/
public function set( $key, $value ) {
if ( array_key_exists( $key, $this->cache ) ) {
- $this->ping( $key ); // push to top
+ $this->ping( $key );
} elseif ( count( $this->cache ) >= $this->maxCacheKeys ) {
reset( $this->cache );
$evictKey = key( $this->cache );
@@ -87,12 +87,11 @@
* @return mixed
*/
public function get( $key ) {
- if ( array_key_exists( $key, $this->cache ) ) {
- $this->ping( $key ); // push to top
- return $this->cache[$key];
- } else {
+ if ( !array_key_exists( $key, $this->cache ) ) {
return null;
}
+ $this->ping( $key );
+ return $this->cache[$key];
}
/**
diff --git a/includes/libs/ProcessCacheLRU.php
b/includes/libs/ProcessCacheLRU.php
index b55ff9d..eec31ce 100644
--- a/includes/libs/ProcessCacheLRU.php
+++ b/includes/libs/ProcessCacheLRU.php
@@ -55,7 +55,7 @@
*/
public function set( $key, $prop, $value ) {
if ( isset( $this->cache[$key] ) ) {
- $this->ping( $key ); // push to top
+ $this->ping( $key );
} elseif ( count( $this->cache ) >= $this->maxCacheKeys ) {
reset( $this->cache );
$evictKey = key( $this->cache );
@@ -94,13 +94,11 @@
* @return mixed
*/
public function get( $key, $prop ) {
- if ( isset( $this->cache[$key][$prop] ) ) {
- // push to top
- $this->ping( $key );
- return $this->cache[$key][$prop];
- } else {
+ if ( !isset( $this->cache[$key][$prop] ) ) {
return null;
}
+ $this->ping( $key );
+ return $this->cache[$key][$prop];
}
/**
@@ -130,7 +128,7 @@
*/
public function resize( $maxKeys ) {
Assert::parameterType( 'integer', $maxKeys, '$maxKeys' );
- Assert::parameter( $maxKeys >= 1, '$maxKeys', 'must be >= 1' );
+ Assert::parameter( $maxKeys > 0, '$maxKeys', 'must be above
zero' );
$this->maxCacheKeys = $maxKeys;
while ( count( $this->cache ) > $this->maxCacheKeys ) {
--
To view, visit https://gerrit.wikimedia.org/r/247509
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I25d276faa555e02feb99e656eb9cb7071f8205c0
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Krinkle <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits