Reduce conditional for calling openssl_random_pseudo_bytes
[lhc/web/wiklou.git] / includes / utils / UIDGenerator.php
index e2de900..9ac5009 100644 (file)
@@ -135,7 +135,7 @@ class UIDGenerator {
                        $time = $info[0];
                        $counter = $info[1];
                }
-               // Take the 46 MSBs of "milliseconds since epoch"
+               // Take the 46 LSBs of "milliseconds since epoch"
                $id_bin = $this->millisecondsSinceEpochBinary( $time );
                // Add a 10 bit counter resulting in 56 bits total
                $id_bin .= str_pad( decbin( $counter ), 10, '0', STR_PAD_LEFT );
@@ -191,7 +191,7 @@ class UIDGenerator {
                        $counter = $info[1];
                        $clkSeq = $info[2];
                }
-               // Take the 46 bits of "milliseconds since epoch"
+               // Take the 46 LSBs of "milliseconds since epoch"
                $id_bin = $this->millisecondsSinceEpochBinary( $time );
                // Add a 20 bit counter resulting in 66 bits total
                $id_bin .= str_pad( decbin( $counter ), 20, '0', STR_PAD_LEFT );
@@ -334,7 +334,7 @@ class UIDGenerator {
         * @see UIDGenerator::newSequentialPerNodeID()
         * @param string $bucket Arbitrary bucket name (should be ASCII)
         * @param int $bits Bit size (16 to 48) of resulting numbers before wrap-around
-        * @param int $count Number of IDs to return (1 to 10000)
+        * @param int $count Number of IDs to return
         * @param int $flags (supports UIDGenerator::QUICK_VOLATILE)
         * @return array Ordered list of float integer values
         * @since 1.23
@@ -350,7 +350,7 @@ class UIDGenerator {
         * @see UIDGenerator::newSequentialPerNodeID()
         * @param string $bucket Arbitrary bucket name (should be ASCII)
         * @param int $bits Bit size (16 to 48) of resulting numbers before wrap-around
-        * @param int $count Number of IDs to return (1 to 10000)
+        * @param int $count Number of IDs to return
         * @param int $flags (supports UIDGenerator::QUICK_VOLATILE)
         * @return array Ordered list of float integer values
         * @throws RuntimeException
@@ -358,8 +358,6 @@ class UIDGenerator {
        protected function getSequentialPerNodeIDs( $bucket, $bits, $count, $flags ) {
                if ( $count <= 0 ) {
                        return array(); // nothing to do
-               } elseif ( $count > 10000 ) {
-                       throw new RuntimeException( "Number of requested IDs ($count) is too high." );
                } elseif ( $bits < 16 || $bits > 48 ) {
                        throw new RuntimeException( "Requested bit size ($bits) is out of range." );
                }
@@ -373,12 +371,9 @@ class UIDGenerator {
                        $cache = ObjectCache::getLocalServerInstance();
                }
                if ( $cache ) {
-                       $counter = $cache->incr( $bucket, $count );
+                       $counter = $cache->incrWithInit( $bucket, $cache::TTL_INDEFINITE, $count, $count );
                        if ( $counter === false ) {
-                               if ( !$cache->add( $bucket, (int)$count ) ) {
-                                       throw new RuntimeException( 'Unable to set value to ' . get_class( $cache ) );
-                               }
-                               $counter = $count;
+                               throw new RuntimeException( 'Unable to set value to ' . get_class( $cache ) );
                        }
                }
 
@@ -531,7 +526,7 @@ class UIDGenerator {
 
        /**
         * @param array $time Result of UIDGenerator::millitime()
-        * @return string 46 MSBs of "milliseconds since epoch" in binary (rolls over in 4201)
+        * @return string 46 LSBs of "milliseconds since epoch" in binary (rolls over in 4201)
         * @throws RuntimeException
         */
        protected function millisecondsSinceEpochBinary( array $time ) {