fast_xs 0.5 → 0.6

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -13,7 +13,7 @@ begin
13
13
  rev = Time.at(rev.split("\n")[1].to_i).strftime('%Y%m%d.%H%M%S')
14
14
  rescue
15
15
  end
16
- version ||= ENV['VERSION'] || '0.5' + (rev && rev.length > 0 ? ".#{rev}" : '')
16
+ version ||= ENV['VERSION'] || '0.6' + (rev && rev.length > 0 ? ".#{rev}" : '')
17
17
  pkg = "#{name}-#{version}"
18
18
  bin = "*.{so,o}"
19
19
  archlib = "lib/#{::Config::CONFIG['arch']}"
@@ -45,7 +45,11 @@ spec = Gem::Specification.new do |s|
45
45
  end
46
46
 
47
47
  if ENV['VERSION']
48
+ # FIXME - look for hoe replacement...
49
+ prev = `git for-each-ref --format='%(refname)' refs/tags | tail -n1`.chomp
50
+ sh("git shortlog #{prev}..HEAD > History.txt");
48
51
  sh('git ls-files > Manifest.txt')
52
+ File.exists?('README.txt') or File.link('README', 'README.txt')
49
53
  hoe = Hoe.new(name, version) do |p|
50
54
  p.author = spec.author
51
55
  p.description = spec.description
@@ -1,53 +1,13 @@
1
- #define VERSION "0.1"
2
-
3
1
  #include <ruby.h>
4
2
  #include <assert.h>
5
3
  #include <sys/time.h>
6
4
  #include <sys/resource.h>
7
5
  #include "ruby_1_9_compat.h"
8
-
9
- /* I don't trust ctype.h when it comes to locale-independence: */
10
- static __inline__ int is_hex(const int x)
11
- {
12
- return (((x) >= '0' && (x) <= '9') ||
13
- ((x) >= 'a' && (x) <= 'f') ||
14
- ((x) >= 'A' && (x) <= 'F'));
15
- }
16
-
17
- static __inline__ int xtoupper(const int x)
18
- {
19
- return (x >= 'a' && x <= 'f') ? (x & ~0x20) : x;
20
- }
21
-
22
- static __inline__ int hexchar_to_int(const int x)
23
- {
24
- return (x < 'A') ? (x - '0') : (xtoupper(x) - 'A' + 10);
25
- }
26
-
27
- static __inline__ int hexpair_to_int(const int x1, const int x2)
28
- {
29
- return ((hexchar_to_int(x1) << 4) | hexchar_to_int(x2));
30
- }
6
+ #include "fast_xs_type.h"
7
+ #include "gcc.h"
31
8
 
32
9
  static ID unpack_id;
33
10
  static VALUE U_fmt, C_fmt;
34
- static rlim_t alloca_limit = 4096; /* very small default */
35
-
36
- #define xs_alloc(size) \
37
- unlikely((size) > alloca_limit) ? malloc(size) : alloca(size)
38
-
39
- #define xs_free(ptr, size) \
40
- do { if (unlikely((size) > alloca_limit)) free(ptr); } while (0)
41
-
42
- /* give GCC hints for better branch prediction
43
- * (we layout branches so that ASCII characters are handled faster) */
44
- #if defined(__GNUC__) && (__GNUC__ >= 3)
45
- # define likely(x) __builtin_expect (!!(x), 1)
46
- # define unlikely(x) __builtin_expect (!!(x), 0)
47
- #else
48
- # define unlikely(x) (x)
49
- # define likely(x) (x)
50
- #endif
51
11
 
52
12
  /* pass-through certain characters for CP-1252 */
53
13
  #define p(x) (x-128)
@@ -172,7 +132,7 @@ static VALUE fast_xs(VALUE self)
172
132
  {
173
133
  long i;
174
134
  VALUE array;
175
- char *s, *c;
135
+ char *c;
176
136
  size_t s_len;
177
137
  VALUE *tmp;
178
138
  VALUE rv;
@@ -197,15 +157,12 @@ static VALUE fast_xs(VALUE self)
197
157
  s_len += bytes_for(n) - 1;
198
158
  }
199
159
 
200
- c = s = unlikely(s_len > alloca_limit) ? malloc(s_len) : alloca(s_len);
160
+ rv = rb_str_new(NULL, s_len);
161
+ c = RSTRING_PTR(rv);
201
162
 
202
163
  for (tmp = RARRAY_PTR(array), i = RARRAY_LEN(array); --i >= 0; tmp++)
203
164
  c += escape(c, NUM2INT(*tmp));
204
165
 
205
- rv = rb_str_new(s, s_len);
206
-
207
- xs_free(s, s_len);
208
-
209
166
  return rv;
210
167
  }
211
168
 
@@ -232,7 +189,8 @@ static VALUE fast_xs_html(VALUE self)
232
189
  new_len += (sizeof("&quot;") - 2);
233
190
  }
234
191
 
235
- new_str = xs_alloc(new_len);
192
+ rv = rb_str_new(NULL, new_len);
193
+ new_str = RSTRING_PTR(rv);
236
194
 
237
195
  #define append_const(buf, x) do { \
238
196
  buf = memcpy(buf, x, sizeof(x) - 1) + sizeof(x) - 1; \
@@ -253,10 +211,6 @@ static VALUE fast_xs_html(VALUE self)
253
211
 
254
212
  #undef append_const
255
213
 
256
- rv = rb_str_new(new_str - new_len, new_len);
257
-
258
- xs_free(new_str - new_len, new_len);
259
-
260
214
  return rv;
261
215
  }
262
216
 
@@ -280,7 +234,8 @@ static inline VALUE _xs_uri_encode(VALUE self, const unsigned int space_to_plus)
280
234
  new_len += 2;
281
235
  }
282
236
 
283
- new_str = xs_alloc(new_len);
237
+ rv = rb_str_new(NULL, new_len);
238
+ new_str = RSTRING_PTR(rv);
284
239
 
285
240
  for (s = RSTRING_PTR(self), i = RSTRING_LEN(self); --i >= 0; ++s) {
286
241
  if (likely(CGI_URI_OK(*s)))
@@ -296,10 +251,6 @@ static inline VALUE _xs_uri_encode(VALUE self, const unsigned int space_to_plus)
296
251
  }
297
252
  }
298
253
 
299
- rv = rb_str_new(new_str - new_len, new_len);
300
-
301
- xs_free(new_str - new_len, new_len);
302
-
303
254
  return rv;
304
255
  }
305
256
 
@@ -341,7 +292,9 @@ static VALUE _uxs_uri(VALUE self, const unsigned int plus_to_space)
341
292
  }
342
293
  }
343
294
 
344
- new_str = xs_alloc(new_len);
295
+ rv = rb_str_new(NULL, new_len);
296
+ new_str = RSTRING_PTR(rv);
297
+
345
298
  for (s = RSTRING_PTR(self), i = RSTRING_LEN(self);
346
299
  --i >= 0;
347
300
  ++s, ++new_str) {
@@ -357,10 +310,6 @@ static VALUE _uxs_uri(VALUE self, const unsigned int plus_to_space)
357
310
  *new_str = *s;
358
311
  }
359
312
 
360
- rv = rb_str_new(new_str - new_len, new_len);
361
-
362
- xs_free(s, new_len);
363
-
364
313
  return rv;
365
314
  }
366
315
 
@@ -371,14 +320,8 @@ static VALUE fast_uxs_cgi(VALUE self)
371
320
 
372
321
  void Init_fast_xs(void)
373
322
  {
374
- struct rlimit rlim;
375
-
376
323
  assert(cp_1252[159 - 128] == 376); /* just in case I skipped a line */
377
324
 
378
- /* fairly conservative stack estimation IMHO... */
379
- if (!getrlimit(RLIMIT_STACK, &rlim) && (rlim.rlim_cur > 0x80000))
380
- alloca_limit = rlim.rlim_cur - (rlim.rlim_cur / 16);
381
-
382
325
  unpack_id = rb_intern("unpack");
383
326
  U_fmt = rb_str_new("U*", 2);
384
327
  C_fmt = rb_str_new("C*", 2);
@@ -0,0 +1,28 @@
1
+ #ifndef FAST_XS_TYPE_H
2
+ #define FAST_XS_TYPE_H
3
+
4
+ /* I don't trust ctype.h when it comes to locale-independence: */
5
+
6
+ static __inline__ int is_hex(const int x)
7
+ {
8
+ return (((x) >= '0' && (x) <= '9') ||
9
+ ((x) >= 'a' && (x) <= 'f') ||
10
+ ((x) >= 'A' && (x) <= 'F'));
11
+ }
12
+
13
+ static __inline__ int xtoupper(const int x)
14
+ {
15
+ return (x >= 'a' && x <= 'f') ? (x & ~0x20) : x;
16
+ }
17
+
18
+ static __inline__ int hexchar_to_int(const int x)
19
+ {
20
+ return (x < 'A') ? (x - '0') : (xtoupper(x) - 'A' + 10);
21
+ }
22
+
23
+ static __inline__ int hexpair_to_int(const int x1, const int x2)
24
+ {
25
+ return ((hexchar_to_int(x1) << 4) | hexchar_to_int(x2));
26
+ }
27
+
28
+ #endif /* FAST_XS_TYPE_H */
data/ext/fast_xs/gcc.h ADDED
@@ -0,0 +1,14 @@
1
+ #ifndef GCC_H
2
+ #define GCC_H
3
+
4
+ /* give GCC hints for better branch prediction
5
+ * (we layout branches so that ASCII characters are handled faster) */
6
+ #if defined(__GNUC__) && (__GNUC__ >= 3)
7
+ # define likely(x) __builtin_expect (!!(x), 1)
8
+ # define unlikely(x) __builtin_expect (!!(x), 0)
9
+ #else
10
+ # define unlikely(x) (x)
11
+ # define likely(x) (x)
12
+ #endif
13
+
14
+ #endif /* GCC_H */
@@ -36,6 +36,7 @@ class TestCgiClassOverrides < Test::Unit::TestCase
36
36
  assert_equal ' ', CGI::unescape('+')
37
37
  assert_equal '+', CGI::unescape('%2B')
38
38
  assert_equal ',', CGI::unescape('%2C')
39
+ assert_equal '%', CGI::unescape('%')
39
40
  assert_equal 'hello-world', CGI::unescape('hello-world')
40
41
  assert_equal 'H3LL0 W0RLD', CGI::unescape('H3LL0+W0RLD')
41
42
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4.7
3
3
  specification_version: 2
4
4
  name: fast_xs
5
5
  version: !ruby/object:Gem::Version
6
- version: "0.5"
7
- date: 2008-01-07 00:00:00 -08:00
6
+ version: "0.6"
7
+ date: 2008-02-20 00:00:00 -08:00
8
8
  summary: excessively fast escaping
9
9
  require_paths:
10
10
  - lib/i486-linux
@@ -48,6 +48,8 @@ files:
48
48
  - ext/fast_xs/fast_xs.c
49
49
  - ext/fast_xs/extconf.rb
50
50
  - ext/fast_xs/ruby_1_9_compat.h
51
+ - ext/fast_xs/fast_xs_type.h
52
+ - ext/fast_xs/gcc.h
51
53
  test_files: []
52
54
 
53
55
  rdoc_options: