lib/memcache.rb in fiveruns-memcache-client-1.5.0.4 vs lib/memcache.rb in fiveruns-memcache-client-1.5.0.5

- old
+ new

@@ -2,43 +2,12 @@ require 'socket' require 'thread' require 'timeout' require 'rubygems' +require 'zlib' -class String - - ## - # Uses the ITU-T polynomial in the CRC32 algorithm. - begin - require 'crc32' - def crc32_ITU_T - CRC32.itu_t(self) - end - rescue LoadError => e - puts "Loading with slow CRC32 ITU-T implementation: #{e.message}" - - def crc32_ITU_T - r = 0xFFFFFFFF - - each_byte do |i| - r ^= i - 8.times do - if (r & 1) != 0 then - r = (r>>1) ^ 0xEDB88320 - else - r >>= 1 - end - end - end - - r ^ 0xFFFFFFFF - end - end - -end - ## # A Ruby client library for memcached. # # This is intended to provide access to basic memcached functionality. It # does not attempt to be complete implementation of the entire API, but it is @@ -498,10 +467,10 @@ ## # Returns an interoperable hash value for +key+. (I think, docs are # sketchy for down servers). def hash_for(key) - (key.crc32_ITU_T >> 16) & 0x7fff + (Zlib.crc32(key) >> 16) & 0x7fff end ## # Performs a raw decr for +cache_key+ from +server+. Returns nil if not # found.