yajl-ruby 0.8.1 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of yajl-ruby might be problematic. Click here for more details.
- data/CHANGELOG.md +3 -0
- data/README.rdoc +1 -1
- data/benchmark/encode.rb +39 -25
- data/benchmark/parse.rb +37 -2
- data/ext/yajl/yajl_ext.h +6 -0
- data/lib/yajl/version.rb +1 -1
- metadata +5 -5
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.8.2 (March 22nd, 2011)
|
4
|
+
* define RSTRING_NOT_MODIFIED for rbx to prevent string caching, making things A LOT faster (100x)
|
5
|
+
|
3
6
|
## 0.8.1 (February 11th, 2011)
|
4
7
|
* fixed a retart bug where Yajl::VERSION wasn't defined when explicitly requiring yajl/http_stream
|
5
8
|
|
data/README.rdoc
CHANGED
@@ -204,7 +204,7 @@ If you plan on embedding the output from the encoder in the DOM, you'll want to
|
|
204
204
|
Meaning the following should be perfectly safe:
|
205
205
|
|
206
206
|
<script type="text/javascript">
|
207
|
-
escaped_str = <%= Yajl::Encoder.encode("</script><script>alert('hi!');</script>", :html_safe => true) %>;
|
207
|
+
var escaped_str = <%= Yajl::Encoder.encode("</script><script>alert('hi!');</script>", :html_safe => true) %>;
|
208
208
|
</script>
|
209
209
|
|
210
210
|
== JSON gem Compatibility API
|
data/benchmark/encode.rb
CHANGED
@@ -10,50 +10,64 @@ begin
|
|
10
10
|
require 'json'
|
11
11
|
rescue LoadError
|
12
12
|
end
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
begin
|
14
|
+
require 'psych'
|
15
|
+
rescue LoadError
|
16
|
+
end
|
17
|
+
begin
|
18
|
+
require 'active_support'
|
19
|
+
rescue LoadError
|
20
|
+
end
|
18
21
|
|
19
22
|
filename = ARGV[0] || 'benchmark/subjects/ohai.json'
|
20
|
-
|
21
|
-
hash = Yajl::Parser.new.parse(json)
|
22
|
-
json.close
|
23
|
+
hash = File.open(filename, 'rb') { |f| Yajl::Parser.new.parse(f.read) }
|
23
24
|
|
24
25
|
times = ARGV[1] ? ARGV[1].to_i : 1000
|
25
26
|
puts "Starting benchmark encoding #{filename} #{times} times\n\n"
|
26
27
|
Benchmark.bmbm { |x|
|
27
28
|
io_encoder = Yajl::Encoder.new
|
28
|
-
|
29
|
-
|
29
|
+
string_encoder = Yajl::Encoder.new
|
30
|
+
|
31
|
+
x.report("Yajl::Encoder#encode (to an IO)") {
|
30
32
|
times.times {
|
31
33
|
io_encoder.encode(hash, StringIO.new)
|
32
34
|
}
|
33
35
|
}
|
34
|
-
|
35
|
-
x.report {
|
36
|
-
puts "Yajl::Encoder#encode (to a String)"
|
36
|
+
x.report("Yajl::Encoder#encode (to a String)") {
|
37
37
|
times.times {
|
38
38
|
output = string_encoder.encode(hash)
|
39
39
|
}
|
40
40
|
}
|
41
41
|
if defined?(JSON)
|
42
|
-
x.report {
|
43
|
-
puts "JSON.generate"
|
42
|
+
x.report("JSON.generate") {
|
44
43
|
times.times {
|
45
44
|
JSON.generate(hash)
|
46
45
|
}
|
47
46
|
}
|
48
47
|
end
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
48
|
+
if defined?(Psych)
|
49
|
+
x.report("Psych.to_json") {
|
50
|
+
times.times {
|
51
|
+
Psych.to_json(hash)
|
52
|
+
}
|
53
|
+
}
|
54
|
+
if defined?(Psych::JSON::Stream)
|
55
|
+
x.report("Psych::JSON::Stream") {
|
56
|
+
times.times {
|
57
|
+
io = StringIO.new
|
58
|
+
stream = Psych::JSON::Stream.new io
|
59
|
+
stream.start
|
60
|
+
stream.push hash
|
61
|
+
stream.finish
|
62
|
+
}
|
63
|
+
}
|
64
|
+
end
|
65
|
+
end
|
66
|
+
if defined?(ActiveSupport::JSON)
|
67
|
+
x.report("ActiveSupport::JSON.encode") {
|
68
|
+
times.times {
|
69
|
+
ActiveSupport::JSON.encode(hash)
|
70
|
+
}
|
71
|
+
}
|
72
|
+
end
|
59
73
|
}
|
data/benchmark/parse.rb
CHANGED
@@ -4,20 +4,25 @@ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
|
|
4
4
|
|
5
5
|
require 'rubygems'
|
6
6
|
require 'benchmark'
|
7
|
+
require 'yaml'
|
7
8
|
require 'yajl'
|
8
9
|
begin
|
9
10
|
require 'json'
|
10
11
|
rescue LoadError
|
11
12
|
end
|
13
|
+
begin
|
14
|
+
require 'psych'
|
15
|
+
rescue LoadError
|
16
|
+
end
|
12
17
|
begin
|
13
18
|
require 'active_support'
|
14
19
|
rescue LoadError
|
15
20
|
end
|
16
21
|
|
17
|
-
filename = ARGV[0] || 'benchmark/subjects/
|
22
|
+
filename = ARGV[0] || 'benchmark/subjects/item.json'
|
18
23
|
json = File.new(filename, 'r')
|
19
24
|
|
20
|
-
times = ARGV[1] ? ARGV[1].to_i :
|
25
|
+
times = ARGV[1] ? ARGV[1].to_i : 10_000
|
21
26
|
puts "Starting benchmark parsing #{File.size(filename)} bytes of JSON data #{times} times\n\n"
|
22
27
|
Benchmark.bmbm { |x|
|
23
28
|
io_parser = Yajl::Parser.new
|
@@ -56,5 +61,35 @@ Benchmark.bmbm { |x|
|
|
56
61
|
}
|
57
62
|
}
|
58
63
|
end
|
64
|
+
x.report {
|
65
|
+
puts "YAML.load (from an IO)"
|
66
|
+
times.times {
|
67
|
+
json.rewind
|
68
|
+
YAML.load(json)
|
69
|
+
}
|
70
|
+
}
|
71
|
+
x.report {
|
72
|
+
puts "YAML.load (from a String)"
|
73
|
+
times.times {
|
74
|
+
json.rewind
|
75
|
+
YAML.load(json.read)
|
76
|
+
}
|
77
|
+
}
|
78
|
+
if defined?(Psych)
|
79
|
+
x.report {
|
80
|
+
puts "Psych.load (from an IO)"
|
81
|
+
times.times {
|
82
|
+
json.rewind
|
83
|
+
Psych.load(json)
|
84
|
+
}
|
85
|
+
}
|
86
|
+
x.report {
|
87
|
+
puts "Psych.load (from a String)"
|
88
|
+
times.times {
|
89
|
+
json.rewind
|
90
|
+
Psych.load(json.read)
|
91
|
+
}
|
92
|
+
}
|
93
|
+
end
|
59
94
|
}
|
60
95
|
json.close
|
data/ext/yajl/yajl_ext.h
CHANGED
@@ -23,6 +23,12 @@
|
|
23
23
|
|
24
24
|
#include "api/yajl_parse.h"
|
25
25
|
#include "api/yajl_gen.h"
|
26
|
+
|
27
|
+
// tell rbx not to use it's caching compat layer
|
28
|
+
// by doing this we're making a promize to RBX that
|
29
|
+
// we'll never modify the pointers we get back from RSTRING_PTR
|
30
|
+
#define RSTRING_NOT_MODIFIED
|
31
|
+
|
26
32
|
#include <ruby.h>
|
27
33
|
|
28
34
|
#ifdef HAVE_RUBY_ENCODING_H
|
data/lib/yajl/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yajl-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 59
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 8
|
9
|
-
-
|
10
|
-
version: 0.8.
|
9
|
+
- 2
|
10
|
+
version: 0.8.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Brian Lopez
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-
|
19
|
+
date: 2011-03-23 00:00:00 -07:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -266,7 +266,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
266
266
|
requirements: []
|
267
267
|
|
268
268
|
rubyforge_project:
|
269
|
-
rubygems_version: 1.
|
269
|
+
rubygems_version: 1.6.2
|
270
270
|
signing_key:
|
271
271
|
specification_version: 3
|
272
272
|
summary: Ruby C bindings to the excellent Yajl JSON stream-based parser library.
|