methodmissing-hwia 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README CHANGED
@@ -1,4 +1,93 @@
1
1
  Attempt at a zippier HashWithIndifferentAccess for Ruby MRI
2
2
  (c) 2009 Lourens Naudé (methodmissing), James Tucker (raggi)
3
3
 
4
- Work in progress
4
+ http://github.com/methodmissing/hwia
5
+
6
+ This library works with Ruby MRI > 1.8.6 && 1.9.2 and is a more efficient implementation of
7
+ ActiveSupport::HashWithIndifferentAccess, which allows interchangeable use of string and symbol
8
+ hash keys.
9
+
10
+ The numbers ?
11
+
12
+ methodmissing:hwia lourens$ rake bench
13
+ (in /Users/lourens/projects/hwia)
14
+ /opt/local/bin/ruby extconf.rb
15
+ checking for rb_thread_blocking_region()... no
16
+ checking for rb_trap_immediate in ruby.h,rubysig.h... yes
17
+ creating Makefile
18
+ make
19
+ gcc -I. -I. -I/opt/local/lib/ruby/1.8/i686-darwin9.5.1 -I. -DHAVE_RB_TRAP_IMMEDIATE -DRUBY18 -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -fno-common -O2 -pipe -fno-common -c hwia.c
20
+ cc -dynamic -bundle -undefined suppress -flat_namespace -o hwia.bundle hwia.o -L. -L/opt/local/lib -L. -ldl -lobjc
21
+ /opt/local/bin/ruby bench/bench.rb
22
+ Rehearsal ------------------------------------------------------------------------------
23
+ StrHash#[:sym] 0.000000 0.000000 0.000000 ( 0.002999)
24
+ HashWithIndifferentAccess#[:sym] 0.020000 0.000000 0.020000 ( 0.021942)
25
+ StrHash#['str'] 0.010000 0.000000 0.010000 ( 0.004590)
26
+ HashWithIndifferentAccess#['str] 0.000000 0.000000 0.000000 ( 0.003842)
27
+ StrHash#key?(:sym) 0.010000 0.000000 0.010000 ( 0.002902)
28
+ HashWithIndifferentAccess#key?(:sym) 0.010000 0.000000 0.010000 ( 0.013906)
29
+ StrHash#key?('str') 0.000000 0.000000 0.000000 ( 0.004245)
30
+ HashWithIndifferentAccess#key?('str') 0.010000 0.000000 0.010000 ( 0.010769)
31
+ StrHash#fetch(:sym) 0.010000 0.000000 0.010000 ( 0.003285)
32
+ HashWithIndifferentAccess#fetch(:sym) 0.020000 0.000000 0.020000 ( 0.019375)
33
+ StrHash#fetch('str') 0.000000 0.000000 0.000000 ( 0.003811)
34
+ HashWithIndifferentAccess#fetch('str') 0.010000 0.000000 0.010000 ( 0.014550)
35
+ StrHash#values_at(:sym) 0.010000 0.000000 0.010000 ( 0.006830)
36
+ HashWithIndifferentAccess#values_at(:sym) 0.020000 0.000000 0.020000 ( 0.020391)
37
+ StrHash#values_at('str') 0.010000 0.000000 0.010000 ( 0.007286)
38
+ HashWithIndifferentAccess#values_at('str') 0.020000 0.000000 0.020000 ( 0.019495)
39
+ StrHash#['str']= 0.000000 0.000000 0.000000 ( 0.004249)
40
+ HashWithIndifferentAccess#['str]= 0.020000 0.000000 0.020000 ( 0.017406)
41
+ StrHash#[:sym]= 0.000000 0.000000 0.000000 ( 0.003898)
42
+ HashWithIndifferentAccess#[:sym]= 0.020000 0.000000 0.020000 ( 0.020366)
43
+ StrHash#update 0.010000 0.000000 0.010000 ( 0.005549)
44
+ HashWithIndifferentAccess#update 0.050000 0.000000 0.050000 ( 0.058935)
45
+ StrHash#dup 0.030000 0.000000 0.030000 ( 0.029752)
46
+ HashWithIndifferentAccess#dup 0.120000 0.000000 0.120000 ( 0.128600)
47
+ StrHash#merge 0.030000 0.000000 0.030000 ( 0.027572)
48
+ HashWithIndifferentAccess#merge 0.180000 0.000000 0.180000 ( 0.179814)
49
+ StrHash#to_hash 0.030000 0.000000 0.030000 ( 0.034352)
50
+ HashWithIndifferentAccess#to_hash 0.040000 0.000000 0.040000 ( 0.038520)
51
+ --------------------------------------------------------------------- total: 0.690000sec
52
+
53
+ user system total real
54
+ StrHash#[:sym] 0.010000 0.000000 0.010000 ( 0.003005)
55
+ HashWithIndifferentAccess#[:sym] 0.020000 0.000000 0.020000 ( 0.020551)
56
+ StrHash#['str'] 0.000000 0.000000 0.000000 ( 0.003312)
57
+ HashWithIndifferentAccess#['str] 0.000000 0.000000 0.000000 ( 0.003213)
58
+ StrHash#key?(:sym) 0.000000 0.000000 0.000000 ( 0.002851)
59
+ HashWithIndifferentAccess#key?(:sym) 0.010000 0.000000 0.010000 ( 0.012139)
60
+ StrHash#key?('str') 0.010000 0.000000 0.010000 ( 0.003496)
61
+ HashWithIndifferentAccess#key?('str') 0.010000 0.000000 0.010000 ( 0.009912)
62
+ StrHash#fetch(:sym) 0.000000 0.000000 0.000000 ( 0.003172)
63
+ HashWithIndifferentAccess#fetch(:sym) 0.020000 0.000000 0.020000 ( 0.017662)
64
+ StrHash#fetch('str') 0.000000 0.000000 0.000000 ( 0.003850)
65
+ HashWithIndifferentAccess#fetch('str') 0.020000 0.000000 0.020000 ( 0.014771)
66
+ StrHash#values_at(:sym) 0.000000 0.000000 0.000000 ( 0.004340)
67
+ HashWithIndifferentAccess#values_at(:sym) 0.030000 0.000000 0.030000 ( 0.020821)
68
+ StrHash#values_at('str') 0.000000 0.000000 0.000000 ( 0.004842)
69
+ HashWithIndifferentAccess#values_at('str') 0.020000 0.000000 0.020000 ( 0.017479)
70
+ StrHash#['str']= 0.010000 0.000000 0.010000 ( 0.004225)
71
+ HashWithIndifferentAccess#['str]= 0.010000 0.000000 0.010000 ( 0.018206)
72
+ StrHash#[:sym]= 0.010000 0.000000 0.010000 ( 0.003825)
73
+ HashWithIndifferentAccess#[:sym]= 0.020000 0.000000 0.020000 ( 0.019323)
74
+ StrHash#update 0.000000 0.000000 0.000000 ( 0.005478)
75
+ HashWithIndifferentAccess#update 0.050000 0.000000 0.050000 ( 0.048082)
76
+ StrHash#dup 0.030000 0.000000 0.030000 ( 0.023855)
77
+ HashWithIndifferentAccess#dup 0.110000 0.000000 0.110000 ( 0.120992)
78
+ StrHash#merge 0.030000 0.000000 0.030000 ( 0.027412)
79
+ HashWithIndifferentAccess#merge 0.180000 0.000000 0.180000 ( 0.173209)
80
+ StrHash#to_hash 0.030000 0.000000 0.030000 ( 0.034561)
81
+ HashWithIndifferentAccess#to_hash 0.030000 0.000000 0.030000 ( 0.025392)
82
+
83
+ Installation
84
+
85
+ 1. sudo gem install methodmissing-hwia
86
+ 2. 'require "hwia_rails"' from within an initializer
87
+
88
+ There's no step three, however, if the gem hasn't built due to github queue delays today (22/08/2009), clone, 'rake gem' and install.
89
+
90
+ It's unlikely you'd see these improvements for most apps as at the framework level, especially for Rails 3.0,
91
+ this mostly negates query params access overheads.Any pointers and refactoring suggestions much appreciated.
92
+
93
+ Have fun, happy hacking!
data/Rakefile CHANGED
@@ -65,4 +65,9 @@ desc "run benchmarks"
65
65
  task :bench do
66
66
  ruby "bench/bench.rb"
67
67
  end
68
- task :bench => :build
68
+ task :bench => :build
69
+
70
+ desc "build gem"
71
+ task :gem do
72
+ sh "gem build hwia.gemspec"
73
+ end
data/ext/hwia/hwia.c CHANGED
@@ -118,7 +118,7 @@ rb_strhash_hash_cmp(VALUE a, VALUE b)
118
118
  TYPE(b) == T_STRING && RBASIC(b)->klass == rb_cString) {
119
119
  return rb_str_cmp(a, b);
120
120
  }
121
- if ((TYPE(a) == T_STRING && RBASIC(a)->klass == rb_cString && SYMBOL_P(b)) || (TYPE(b) == T_STRING && RBASIC(b)->klass == rb_cString && SYMBOL_P(a))) {
121
+ if (SYMBOL_P(b) && (TYPE(a) == T_STRING && RBASIC(a)->klass == rb_cString) || (SYMBOL_P(a) && TYPE(b) == T_STRING && RBASIC(b)->klass == rb_cString)) {
122
122
  return rb_strhash_cmp(a, b);
123
123
  }
124
124
  if (a == Qundef || b == Qundef) return -1;
@@ -161,7 +161,6 @@ static int
161
161
  rb_strhash_hash(VALUE a)
162
162
  {
163
163
  VALUE hval, hnum;
164
-
165
164
  switch (TYPE(a)) {
166
165
  case T_FIXNUM:
167
166
  #ifdef RUBY18
data/hwia.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "hwia"
3
- s.version = "1.0.0"
3
+ s.version = "1.0.1"
4
4
  s.date = "2009-08-23"
5
5
  s.summary = "A faster HashWithIndifferentAccess (hwia) for MRI"
6
6
  s.email = "lourens@methodmissing.com"
data/lib/hwia_rails.rb CHANGED
@@ -8,13 +8,19 @@ end
8
8
  class StrHash
9
9
  def stringify_keys!; self end
10
10
  def symbolize_keys!; self end
11
- def to_options!; self end
11
+ def to_options!; self end
12
+
13
+ protected
14
+ # AS test suite compat only
15
+ def convert_key(key)
16
+ key.kind_of?(Symbol) ? key.to_s : key
17
+ end
12
18
  end
13
19
 
14
20
  begin
15
- old, $VERBOSE = $VERBOSE, nil
16
- ActiveSupport::HashWithIndifferentAccess = StrHash
17
- HashWithIndifferentAccess = ActiveSupport::HashWithIndifferentAccess
21
+ old, $VERBOSE = $VERBOSE, nil
22
+ ActiveSupport::HashWithIndifferentAccess = StrHash
23
+ HashWithIndifferentAccess = ActiveSupport::HashWithIndifferentAccess
18
24
  ensure
19
25
  $VERBOSE = old
20
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: methodmissing-hwia
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Lourens Naud\xC3\xA9 (methodmissing)"