Skip to content

Commit

Permalink
Use Zlib.crc32 instead of native extension. Prepare for 1.5.0.5 release.
Browse files Browse the repository at this point in the history
  • Loading branch information
mperham committed Nov 25, 2008
1 parent 9c291ad commit 9f81841
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 90 deletions.
5 changes: 5 additions & 0 deletions History.txt
@@ -1,3 +1,8 @@
= 1.5.0.5

* Remove native C CRC32_ITU_T extension in favor of Zlib's crc32 method.
memcache-client is now pure Ruby again and will work with JRuby and Rubinius.

= 1.5.0.4

* Get test suite working again (packagethief)
Expand Down
38 changes: 0 additions & 38 deletions ext/crc32/crc32.c

This file was deleted.

5 changes: 0 additions & 5 deletions ext/crc32/extconf.rb

This file was deleted.

35 changes: 2 additions & 33 deletions lib/memcache.rb
Expand Up @@ -4,38 +4,7 @@
require 'thread'
require 'timeout'
require 'rubygems'

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
require 'zlib'

##
# A Ruby client library for memcached.
Expand Down Expand Up @@ -500,7 +469,7 @@ def get_server_for_key(key)
# sketchy for down servers).

def hash_for(key)
(key.crc32_ITU_T >> 16) & 0x7fff
(Zlib.crc32(key) >> 16) & 0x7fff
end

##
Expand Down
5 changes: 2 additions & 3 deletions memcache-client.gemspec
@@ -1,15 +1,14 @@
Gem::Specification.new do |s|
s.name = 'memcache-client'
s.version = '1.5.0.4'
s.version = '1.5.0.5'
s.authors = ['Eric Hodel', 'Robert Cottrell', 'Mike Perham']
s.email = 'mperham@gmail.com'
s.homepage = 'http://github.com/fiveruns/memcache-client'
s.summary = 'A Ruby-based memcached client library'
s.description = s.summary
s.extensions << 'ext/crc32/extconf.rb'

s.require_path = 'lib'

s.files = ["README.txt", "License.txt", "History.txt", "Rakefile", "lib/memcache.rb", "lib/memcache_util.rb", "ext/crc32/crc32.c"]
s.files = ["README.txt", "License.txt", "History.txt", "Rakefile", "lib/memcache.rb", "lib/memcache_util.rb"]
s.test_files = ["test/test_mem_cache.rb"]
end
11 changes: 0 additions & 11 deletions test/test_mem_cache.rb
Expand Up @@ -164,17 +164,6 @@ def test_cache_get_multi_bad_state
assert_match /get my_namespace:key\r\n/, server.socket.written.string
end

def test_crc32_ITU_T
assert_equal 0, ''.crc32_ITU_T
# First value is the fast C version, last value is the pure Ruby version
assert_in [-886631737, 1260851911], 'my_namespace:key'.crc32_ITU_T
assert_in [-224284233, 870540390], 'my_name√space:key'.crc32_ITU_T
end

def assert_in(possible_values, value)
assert possible_values.include?(value), "#{possible_values.inspect} should contain #{value}"
end

def test_initialize
cache = MemCache.new :namespace => 'my_namespace', :readonly => true

Expand Down

0 comments on commit 9f81841

Please sign in to comment.