Legoktm has uploaded a new change for review.
https://gerrit.wikimedia.org/r/287011
Change subject: Bump wikimedia/cdb to 1.4.0
......................................................................
Bump wikimedia/cdb to 1.4.0
Change-Id: I61cf76132406e9ea61fc50edaa5dfa26765f0ec4
---
M composer.json
M composer.lock
M composer/autoload_classmap.php
M composer/installed.json
A wikimedia/cdb/src/Reader/Hash.php
M wikimedia/cdb/src/Reader/PHP.php
6 files changed, 208 insertions(+), 69 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/vendor
refs/changes/11/287011/1
diff --git a/composer.json b/composer.json
index d058eb0..ea137bf 100644
--- a/composer.json
+++ b/composer.json
@@ -34,7 +34,7 @@
"wikimedia/assert": "0.2.2",
"wikimedia/avro": "1.7.7",
"wikimedia/base-convert": "1.0.1",
- "wikimedia/cdb": "1.3.0",
+ "wikimedia/cdb": "1.4.0",
"wikimedia/cldr-plural-rule-parser": "1.0.0",
"wikimedia/composer-merge-plugin": "1.3.1",
"wikimedia/html-formatter": "1.0.1",
diff --git a/composer.lock b/composer.lock
index bdd8ac6..1b2b07d 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,8 +4,8 @@
"Read more about it at
https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
- "hash": "d4b69794468f794a8350339881319948",
- "content-hash": "fbadb58818d15bd051e858b533bf2252",
+ "hash": "b409fa5095e26ed34530b951698cc515",
+ "content-hash": "5e0b25793682fc5b32f000bdaac041f8",
"packages": [
{
"name": "composer/semver",
@@ -1284,24 +1284,25 @@
},
{
"name": "wikimedia/cdb",
- "version": "1.3.0",
+ "version": "1.4.0",
"source": {
"type": "git",
"url": "https://github.com/wikimedia/cdb.git",
- "reference": "68f8fd495ca94ca0e965dd511e234893c515bb95"
+ "reference": "de73728295f8452465dbb5ec2b680427d557e61b"
},
"dist": {
"type": "zip",
- "url":
"https://api.github.com/repos/wikimedia/cdb/zipball/68f8fd495ca94ca0e965dd511e234893c515bb95",
- "reference": "68f8fd495ca94ca0e965dd511e234893c515bb95",
+ "url":
"https://api.github.com/repos/wikimedia/cdb/zipball/de73728295f8452465dbb5ec2b680427d557e61b",
+ "reference": "de73728295f8452465dbb5ec2b680427d557e61b",
"shasum": ""
},
"require": {
- "php": ">=5.3.2"
+ "php": ">=5.3.2",
+ "wikimedia/assert": "~0.2.2"
},
"require-dev": {
"jakub-onderka/php-parallel-lint": "0.9",
- "mediawiki/mediawiki-codesniffer": "0.3.0",
+ "mediawiki/mediawiki-codesniffer": "0.5.0",
"phpunit/phpunit": "4.6.*"
},
"type": "library",
@@ -1315,6 +1316,9 @@
"GPL-2.0+"
],
"authors": [
+ {
+ "name": "Daniel Kinzler"
+ },
{
"name": "Tim Starling",
"email": "[email protected]"
@@ -1330,7 +1334,7 @@
],
"description": "Constant Database (CDB) wrapper library for PHP.
Provides pure-PHP fallback when dba_* functions are absent.",
"homepage": "https://www.mediawiki.org/wiki/CDB",
- "time": "2015-09-08 19:53:04"
+ "time": "2016-05-04 21:47:24"
},
{
"name": "wikimedia/cldr-plural-rule-parser",
diff --git a/composer/autoload_classmap.php b/composer/autoload_classmap.php
index b219484..3af156c 100644
--- a/composer/autoload_classmap.php
+++ b/composer/autoload_classmap.php
@@ -53,6 +53,7 @@
'Cdb\\Exception' => $vendorDir . '/wikimedia/cdb/src/Exception.php',
'Cdb\\Reader' => $vendorDir . '/wikimedia/cdb/src/Reader.php',
'Cdb\\Reader\\DBA' => $vendorDir . '/wikimedia/cdb/src/Reader/DBA.php',
+ 'Cdb\\Reader\\Hash' => $vendorDir . '/wikimedia/cdb/src/Reader/Hash.php',
'Cdb\\Reader\\PHP' => $vendorDir . '/wikimedia/cdb/src/Reader/PHP.php',
'Cdb\\Util' => $vendorDir . '/wikimedia/cdb/src/Util.php',
'Cdb\\Writer' => $vendorDir . '/wikimedia/cdb/src/Writer.php',
diff --git a/composer/installed.json b/composer/installed.json
index e593582..496237a 100644
--- a/composer/installed.json
+++ b/composer/installed.json
@@ -820,58 +820,6 @@
"homepage": "https://www.mediawiki.org/wiki/base_convert"
},
{
- "name": "wikimedia/cdb",
- "version": "1.3.0",
- "version_normalized": "1.3.0.0",
- "source": {
- "type": "git",
- "url": "https://github.com/wikimedia/cdb.git",
- "reference": "68f8fd495ca94ca0e965dd511e234893c515bb95"
- },
- "dist": {
- "type": "zip",
- "url":
"https://api.github.com/repos/wikimedia/cdb/zipball/68f8fd495ca94ca0e965dd511e234893c515bb95",
- "reference": "68f8fd495ca94ca0e965dd511e234893c515bb95",
- "shasum": ""
- },
- "require": {
- "php": ">=5.3.2"
- },
- "require-dev": {
- "jakub-onderka/php-parallel-lint": "0.9",
- "mediawiki/mediawiki-codesniffer": "0.3.0",
- "phpunit/phpunit": "4.6.*"
- },
- "time": "2015-09-08 19:53:04",
- "type": "library",
- "installation-source": "dist",
- "autoload": {
- "classmap": [
- "src/"
- ]
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "GPL-2.0+"
- ],
- "authors": [
- {
- "name": "Tim Starling",
- "email": "[email protected]"
- },
- {
- "name": "Chad Horohoe",
- "email": "[email protected]"
- },
- {
- "name": "Ori Livneh",
- "email": "[email protected]"
- }
- ],
- "description": "Constant Database (CDB) wrapper library for PHP.
Provides pure-PHP fallback when dba_* functions are absent.",
- "homepage": "https://www.mediawiki.org/wiki/CDB"
- },
- {
"name": "wikimedia/cldr-plural-rule-parser",
"version": "v1.0.0",
"version_normalized": "1.0.0.0",
@@ -1876,5 +1824,61 @@
],
"description": "Efficiently match IP addresses against a set of CIDR
specifications.",
"homepage": "https://github.com/wikimedia/IPSet"
+ },
+ {
+ "name": "wikimedia/cdb",
+ "version": "1.4.0",
+ "version_normalized": "1.4.0.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/wikimedia/cdb.git",
+ "reference": "de73728295f8452465dbb5ec2b680427d557e61b"
+ },
+ "dist": {
+ "type": "zip",
+ "url":
"https://api.github.com/repos/wikimedia/cdb/zipball/de73728295f8452465dbb5ec2b680427d557e61b",
+ "reference": "de73728295f8452465dbb5ec2b680427d557e61b",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.2",
+ "wikimedia/assert": "~0.2.2"
+ },
+ "require-dev": {
+ "jakub-onderka/php-parallel-lint": "0.9",
+ "mediawiki/mediawiki-codesniffer": "0.5.0",
+ "phpunit/phpunit": "4.6.*"
+ },
+ "time": "2016-05-04 21:47:24",
+ "type": "library",
+ "installation-source": "dist",
+ "autoload": {
+ "classmap": [
+ "src/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "GPL-2.0+"
+ ],
+ "authors": [
+ {
+ "name": "Daniel Kinzler"
+ },
+ {
+ "name": "Tim Starling",
+ "email": "[email protected]"
+ },
+ {
+ "name": "Chad Horohoe",
+ "email": "[email protected]"
+ },
+ {
+ "name": "Ori Livneh",
+ "email": "[email protected]"
+ }
+ ],
+ "description": "Constant Database (CDB) wrapper library for PHP.
Provides pure-PHP fallback when dba_* functions are absent.",
+ "homepage": "https://www.mediawiki.org/wiki/CDB"
}
]
diff --git a/wikimedia/cdb/src/Reader/Hash.php
b/wikimedia/cdb/src/Reader/Hash.php
new file mode 100644
index 0000000..3010305
--- /dev/null
+++ b/wikimedia/cdb/src/Reader/Hash.php
@@ -0,0 +1,114 @@
+<?php
+
+namespace Cdb\Reader;
+
+use Cdb\Reader;
+use Wikimedia\Assert\Assert;
+
+/**
+ * Hash implements the CdbReader interface based on an associative
+ * PHP array (a.k.a "hash").
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+/**
+ * Hash implements the CdbReader interface based on an associative
+ * PHP array (a.k.a "hash").
+ */
+class Hash extends Reader {
+
+ /**
+ * @var string
+ */
+ private $data;
+
+ /**
+ * A queue of keys to return from nextkey(),
+ * initialized by firstkey();
+ *
+ * @var string[]|null
+ */
+ private $keys = null;
+
+ /**
+ * Create the object and open the file
+ *
+ * @param string[] $data An associative PHP array.
+ */
+ public function __construct( $data ) {
+ Assert::parameterType( 'array', $data, '$data' );
+ Assert::parameterElementType( 'string', $data, '$data' );
+
+ $this->data = $data;
+ }
+
+ /**
+ * Close the file. Optional, you can just let the variable go out of
scope.
+ */
+ public function close() {
+ $this->data = array();
+ $this->keys = null;
+ }
+
+ /**
+ * Get a value with a given key. Only string values are supported.
+ *
+ * @param string $key
+ *
+ * @return bool|string The value associated with $key, or false if $key
is not known.
+ */
+ public function get( $key ) {
+ return isset( $this->data[ $key ] ) ? $this->data[ $key ] :
false;
+ }
+
+ /**
+ * Check whether key exists
+ *
+ * @param string $key
+ *
+ * @return bool
+ */
+ public function exists( $key ) {
+ return isset( $this->data[ $key ] );
+ }
+
+ /**
+ * Fetch first key
+ *
+ * @return string
+ */
+ public function firstkey() {
+ $this->keys = array_keys( $this->data );
+ return $this->nextkey();
+ }
+
+ /**
+ * Fetch next key
+ *
+ * @return string
+ */
+ public function nextkey() {
+ if ( $this->keys === null ) {
+ return $this->firstkey();
+ }
+
+ return empty( $this->keys ) ? false : array_shift( $this->keys
);
+ }
+
+}
diff --git a/wikimedia/cdb/src/Reader/PHP.php b/wikimedia/cdb/src/Reader/PHP.php
index 0f0d36e..c388141 100644
--- a/wikimedia/cdb/src/Reader/PHP.php
+++ b/wikimedia/cdb/src/Reader/PHP.php
@@ -36,8 +36,8 @@
/** @var string The file name of the CDB file. **/
protected $fileName;
- /** @var string First 2048b of CDB file, containing the hash table. **/
- protected $hashTable;
+ /** @var string First 2048b of CDB file, containing pointers to hash
table. **/
+ protected $index;
/** @var int Offset in file where value of found key starts. **/
protected $dataPos;
@@ -47,6 +47,9 @@
/** @var int File position indicator when iterating over keys. **/
protected $keyIterPos = 2048;
+
+ /** @var int Offset in file where hash tables start. **/
+ protected $keyIterStop;
/** @var string Read buffer for CDB file. **/
protected $buf;
@@ -70,8 +73,8 @@
if ( !$this->handle ) {
throw new Exception( 'Unable to open CDB file "' .
$this->fileName . '".' );
}
- $this->hashTable = fread( $this->handle, 2048 );
- if ( strlen( $this->hashTable ) !== 2048 ) {
+ $this->index = fread( $this->handle, 2048 );
+ if ( strlen( $this->index ) !== 2048 ) {
throw new Exception( 'CDB file contains fewer than 2048
bytes of data.' );
}
}
@@ -115,7 +118,7 @@
// The first 2048 bytes are the lookup table, which is read into
// memory on initialization.
if ( $end <= 2048 ) {
- return substr( $this->hashTable, $start, $len );
+ return substr( $this->index, $start, $len );
}
// Read data from the internal buffer first.
@@ -281,9 +284,19 @@
/**
* Get the first key from the CDB file and reset the key iterator.
*
- * @return string Key.
+ * @return string|bool Key, or false if no keys in file.
*/
public function firstkey() {
+ $this->keyIterPos = 4;
+
+ if ( !$this->keyIterStop ) {
+ $pos = INF;
+ for ( $i = 0; $i < 2048; $i+= 8 ) {
+ $pos = min( $this->readInt31( $i ), $pos );
+ }
+ $this->keyIterStop = $pos;
+ }
+
$this->keyIterPos = 2048;
return $this->nextkey();
}
@@ -291,9 +304,12 @@
/**
* Get the next key from the CDB file.
*
- * @return string Key.
+ * @return string|bool Key, or false if no more keys.
*/
public function nextkey() {
+ if ( $this->keyIterPos >= $this->keyIterStop ) {
+ return false;
+ }
$keyLen = $this->readInt31( $this->keyIterPos );
$dataLen = $this->readInt31( $this->keyIterPos + 4 );
$key = $this->read( $this->keyIterPos + 8, $keyLen );
--
To view, visit https://gerrit.wikimedia.org/r/287011
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I61cf76132406e9ea61fc50edaa5dfa26765f0ec4
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/vendor
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits