oj 2.0.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +17 -23
  3. data/README.md +74 -425
  4. data/ext/oj/buf.h +103 -0
  5. data/ext/oj/cache8.c +4 -0
  6. data/ext/oj/circarray.c +68 -0
  7. data/ext/oj/circarray.h +23 -0
  8. data/ext/oj/code.c +227 -0
  9. data/ext/oj/code.h +40 -0
  10. data/ext/oj/compat.c +243 -0
  11. data/ext/oj/custom.c +1097 -0
  12. data/ext/oj/dump.c +766 -1534
  13. data/ext/oj/dump.h +92 -0
  14. data/ext/oj/dump_compat.c +937 -0
  15. data/ext/oj/dump_leaf.c +254 -0
  16. data/ext/oj/dump_object.c +810 -0
  17. data/ext/oj/dump_rails.c +329 -0
  18. data/ext/oj/dump_strict.c +416 -0
  19. data/ext/oj/encode.h +51 -0
  20. data/ext/oj/err.c +57 -0
  21. data/ext/oj/err.h +70 -0
  22. data/ext/oj/extconf.rb +17 -7
  23. data/ext/oj/fast.c +213 -180
  24. data/ext/oj/hash.c +163 -0
  25. data/ext/oj/hash.h +46 -0
  26. data/ext/oj/hash_test.c +512 -0
  27. data/ext/oj/mimic_json.c +817 -0
  28. data/ext/oj/mimic_rails.c +806 -0
  29. data/ext/oj/mimic_rails.h +17 -0
  30. data/ext/oj/object.c +752 -0
  31. data/ext/oj/odd.c +230 -0
  32. data/ext/oj/odd.h +44 -0
  33. data/ext/oj/oj.c +1288 -929
  34. data/ext/oj/oj.h +240 -69
  35. data/ext/oj/parse.c +1014 -0
  36. data/ext/oj/parse.h +92 -0
  37. data/ext/oj/reader.c +223 -0
  38. data/ext/oj/reader.h +151 -0
  39. data/ext/oj/resolve.c +127 -0
  40. data/ext/oj/{cache.h → resolve.h} +6 -13
  41. data/ext/oj/rxclass.c +133 -0
  42. data/ext/oj/rxclass.h +27 -0
  43. data/ext/oj/saj.c +77 -175
  44. data/ext/oj/scp.c +224 -0
  45. data/ext/oj/sparse.c +911 -0
  46. data/ext/oj/stream_writer.c +301 -0
  47. data/ext/oj/strict.c +162 -0
  48. data/ext/oj/string_writer.c +480 -0
  49. data/ext/oj/val_stack.c +98 -0
  50. data/ext/oj/val_stack.h +188 -0
  51. data/lib/oj/active_support_helper.rb +41 -0
  52. data/lib/oj/bag.rb +6 -10
  53. data/lib/oj/easy_hash.rb +52 -0
  54. data/lib/oj/json.rb +172 -0
  55. data/lib/oj/mimic.rb +260 -5
  56. data/lib/oj/saj.rb +13 -10
  57. data/lib/oj/schandler.rb +142 -0
  58. data/lib/oj/state.rb +131 -0
  59. data/lib/oj/version.rb +1 -1
  60. data/lib/oj.rb +11 -23
  61. data/pages/Advanced.md +22 -0
  62. data/pages/Compatibility.md +25 -0
  63. data/pages/Custom.md +23 -0
  64. data/pages/Encoding.md +65 -0
  65. data/pages/JsonGem.md +79 -0
  66. data/pages/Modes.md +140 -0
  67. data/pages/Options.md +250 -0
  68. data/pages/Rails.md +60 -0
  69. data/pages/Security.md +20 -0
  70. data/test/_test_active.rb +76 -0
  71. data/test/_test_active_mimic.rb +96 -0
  72. data/test/_test_mimic_rails.rb +126 -0
  73. data/test/activesupport4/decoding_test.rb +105 -0
  74. data/test/activesupport4/encoding_test.rb +531 -0
  75. data/test/activesupport4/test_helper.rb +41 -0
  76. data/test/activesupport5/decoding_test.rb +125 -0
  77. data/test/activesupport5/encoding_test.rb +483 -0
  78. data/test/activesupport5/encoding_test_cases.rb +90 -0
  79. data/test/activesupport5/test_helper.rb +50 -0
  80. data/test/activesupport5/time_zone_test_helpers.rb +24 -0
  81. data/test/helper.rb +27 -0
  82. data/test/isolated/shared.rb +310 -0
  83. data/test/isolated/test_mimic_after.rb +13 -0
  84. data/test/isolated/test_mimic_alone.rb +12 -0
  85. data/test/isolated/test_mimic_as_json.rb +45 -0
  86. data/test/isolated/test_mimic_before.rb +13 -0
  87. data/test/isolated/test_mimic_define.rb +28 -0
  88. data/test/isolated/test_mimic_rails_after.rb +22 -0
  89. data/test/isolated/test_mimic_rails_before.rb +21 -0
  90. data/test/isolated/test_mimic_redefine.rb +15 -0
  91. data/test/json_gem/json_addition_test.rb +216 -0
  92. data/test/json_gem/json_common_interface_test.rb +143 -0
  93. data/test/json_gem/json_encoding_test.rb +109 -0
  94. data/test/json_gem/json_ext_parser_test.rb +20 -0
  95. data/test/json_gem/json_fixtures_test.rb +35 -0
  96. data/test/json_gem/json_generator_test.rb +383 -0
  97. data/test/json_gem/json_generic_object_test.rb +90 -0
  98. data/test/json_gem/json_parser_test.rb +470 -0
  99. data/test/json_gem/json_string_matching_test.rb +42 -0
  100. data/test/json_gem/test_helper.rb +18 -0
  101. data/test/perf_compat.rb +130 -0
  102. data/test/perf_fast.rb +9 -9
  103. data/test/perf_file.rb +64 -0
  104. data/test/{perf_obj.rb → perf_object.rb} +24 -10
  105. data/test/perf_scp.rb +151 -0
  106. data/test/perf_strict.rb +32 -113
  107. data/test/sample.rb +2 -3
  108. data/test/test_compat.rb +474 -0
  109. data/test/test_custom.rb +355 -0
  110. data/test/test_debian.rb +53 -0
  111. data/test/test_fast.rb +66 -16
  112. data/test/test_file.rb +237 -0
  113. data/test/test_gc.rb +49 -0
  114. data/test/test_hash.rb +29 -0
  115. data/test/test_null.rb +376 -0
  116. data/test/test_object.rb +1010 -0
  117. data/test/test_saj.rb +16 -16
  118. data/test/test_scp.rb +417 -0
  119. data/test/test_strict.rb +410 -0
  120. data/test/test_various.rb +815 -0
  121. data/test/test_writer.rb +308 -0
  122. data/test/tests.rb +9 -902
  123. data/test/tests_mimic.rb +14 -0
  124. data/test/tests_mimic_addition.rb +7 -0
  125. metadata +253 -38
  126. data/ext/oj/cache.c +0 -148
  127. data/ext/oj/foo.rb +0 -6
  128. data/ext/oj/load.c +0 -1049
  129. data/test/a.rb +0 -38
  130. data/test/perf1.rb +0 -64
  131. data/test/perf2.rb +0 -76
  132. data/test/perf_obj_old.rb +0 -213
  133. data/test/test_mimic.rb +0 -208
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ $: << File.dirname(__FILE__)
5
+ $: << File.join(File.dirname(__FILE__), 'json_gem')
6
+
7
+ require 'json_common_interface_test'
8
+ require 'json_encoding_test'
9
+ require 'json_ext_parser_test'
10
+ require 'json_fixtures_test'
11
+ require 'json_generator_test'
12
+ require 'json_generic_object_test'
13
+ require 'json_parser_test'
14
+ require 'json_string_matching_test'
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ $: << File.dirname(__FILE__)
5
+ $: << File.join(File.dirname(__FILE__), 'json_gem')
6
+
7
+ require 'json_addition_test'
metadata CHANGED
@@ -1,53 +1,186 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oj
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
5
- prerelease:
4
+ version: 3.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Peter Ohler
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-12-18 00:00:00.000000000 Z
13
- dependencies: []
14
- description: ! 'The fastest JSON parser and object serializer. '
11
+ date: 2017-04-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake-compiler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: wwtd
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: 'The fastest JSON parser and object serializer. '
15
56
  email: peter@ohler.com
16
57
  executables: []
17
58
  extensions:
18
59
  - ext/oj/extconf.rb
19
60
  extra_rdoc_files:
20
61
  - README.md
62
+ - pages/Advanced.md
63
+ - pages/Compatibility.md
64
+ - pages/Custom.md
65
+ - pages/Encoding.md
66
+ - pages/JsonGem.md
67
+ - pages/Modes.md
68
+ - pages/Options.md
69
+ - pages/Rails.md
70
+ - pages/Security.md
21
71
  files:
22
- - lib/oj/bag.rb
23
- - lib/oj/error.rb
24
- - lib/oj/mimic.rb
25
- - lib/oj/saj.rb
26
- - lib/oj/version.rb
27
- - lib/oj.rb
28
- - ext/oj/extconf.rb
29
- - ext/oj/foo.rb
30
- - ext/oj/cache.h
31
- - ext/oj/cache8.h
32
- - ext/oj/oj.h
33
- - ext/oj/cache.c
72
+ - LICENSE
73
+ - README.md
74
+ - ext/oj/buf.h
34
75
  - ext/oj/cache8.c
76
+ - ext/oj/cache8.h
77
+ - ext/oj/circarray.c
78
+ - ext/oj/circarray.h
79
+ - ext/oj/code.c
80
+ - ext/oj/code.h
81
+ - ext/oj/compat.c
82
+ - ext/oj/custom.c
35
83
  - ext/oj/dump.c
84
+ - ext/oj/dump.h
85
+ - ext/oj/dump_compat.c
86
+ - ext/oj/dump_leaf.c
87
+ - ext/oj/dump_object.c
88
+ - ext/oj/dump_rails.c
89
+ - ext/oj/dump_strict.c
90
+ - ext/oj/encode.h
91
+ - ext/oj/err.c
92
+ - ext/oj/err.h
93
+ - ext/oj/extconf.rb
36
94
  - ext/oj/fast.c
37
- - ext/oj/load.c
95
+ - ext/oj/hash.c
96
+ - ext/oj/hash.h
97
+ - ext/oj/hash_test.c
98
+ - ext/oj/mimic_json.c
99
+ - ext/oj/mimic_rails.c
100
+ - ext/oj/mimic_rails.h
101
+ - ext/oj/object.c
102
+ - ext/oj/odd.c
103
+ - ext/oj/odd.h
38
104
  - ext/oj/oj.c
105
+ - ext/oj/oj.h
106
+ - ext/oj/parse.c
107
+ - ext/oj/parse.h
108
+ - ext/oj/reader.c
109
+ - ext/oj/reader.h
110
+ - ext/oj/resolve.c
111
+ - ext/oj/resolve.h
112
+ - ext/oj/rxclass.c
113
+ - ext/oj/rxclass.h
39
114
  - ext/oj/saj.c
40
- - test/a.rb
115
+ - ext/oj/scp.c
116
+ - ext/oj/sparse.c
117
+ - ext/oj/stream_writer.c
118
+ - ext/oj/strict.c
119
+ - ext/oj/string_writer.c
120
+ - ext/oj/val_stack.c
121
+ - ext/oj/val_stack.h
122
+ - lib/oj.rb
123
+ - lib/oj/active_support_helper.rb
124
+ - lib/oj/bag.rb
125
+ - lib/oj/easy_hash.rb
126
+ - lib/oj/error.rb
127
+ - lib/oj/json.rb
128
+ - lib/oj/mimic.rb
129
+ - lib/oj/saj.rb
130
+ - lib/oj/schandler.rb
131
+ - lib/oj/state.rb
132
+ - lib/oj/version.rb
133
+ - pages/Advanced.md
134
+ - pages/Compatibility.md
135
+ - pages/Custom.md
136
+ - pages/Encoding.md
137
+ - pages/JsonGem.md
138
+ - pages/Modes.md
139
+ - pages/Options.md
140
+ - pages/Rails.md
141
+ - pages/Security.md
142
+ - test/_test_active.rb
143
+ - test/_test_active_mimic.rb
144
+ - test/_test_mimic_rails.rb
145
+ - test/activesupport4/decoding_test.rb
146
+ - test/activesupport4/encoding_test.rb
147
+ - test/activesupport4/test_helper.rb
148
+ - test/activesupport5/decoding_test.rb
149
+ - test/activesupport5/encoding_test.rb
150
+ - test/activesupport5/encoding_test_cases.rb
151
+ - test/activesupport5/test_helper.rb
152
+ - test/activesupport5/time_zone_test_helpers.rb
41
153
  - test/files.rb
154
+ - test/helper.rb
155
+ - test/isolated/shared.rb
156
+ - test/isolated/test_mimic_after.rb
157
+ - test/isolated/test_mimic_alone.rb
158
+ - test/isolated/test_mimic_as_json.rb
159
+ - test/isolated/test_mimic_before.rb
160
+ - test/isolated/test_mimic_define.rb
161
+ - test/isolated/test_mimic_rails_after.rb
162
+ - test/isolated/test_mimic_rails_before.rb
163
+ - test/isolated/test_mimic_redefine.rb
164
+ - test/json_gem/json_addition_test.rb
165
+ - test/json_gem/json_common_interface_test.rb
166
+ - test/json_gem/json_encoding_test.rb
167
+ - test/json_gem/json_ext_parser_test.rb
168
+ - test/json_gem/json_fixtures_test.rb
169
+ - test/json_gem/json_generator_test.rb
170
+ - test/json_gem/json_generic_object_test.rb
171
+ - test/json_gem/json_parser_test.rb
172
+ - test/json_gem/json_string_matching_test.rb
173
+ - test/json_gem/test_helper.rb
42
174
  - test/perf.rb
43
- - test/perf1.rb
44
- - test/perf2.rb
175
+ - test/perf_compat.rb
45
176
  - test/perf_fast.rb
46
- - test/perf_obj.rb
47
- - test/perf_obj_old.rb
177
+ - test/perf_file.rb
178
+ - test/perf_object.rb
48
179
  - test/perf_saj.rb
180
+ - test/perf_scp.rb
49
181
  - test/perf_simple.rb
50
182
  - test/perf_strict.rb
183
+ - test/sample.rb
51
184
  - test/sample/change.rb
52
185
  - test/sample/dir.rb
53
186
  - test/sample/doc.rb
@@ -60,40 +193,122 @@ files:
60
193
  - test/sample/rect.rb
61
194
  - test/sample/shape.rb
62
195
  - test/sample/text.rb
63
- - test/sample.rb
64
196
  - test/sample_json.rb
197
+ - test/test_compat.rb
198
+ - test/test_custom.rb
199
+ - test/test_debian.rb
65
200
  - test/test_fast.rb
66
- - test/test_mimic.rb
201
+ - test/test_file.rb
202
+ - test/test_gc.rb
203
+ - test/test_hash.rb
204
+ - test/test_null.rb
205
+ - test/test_object.rb
67
206
  - test/test_saj.rb
207
+ - test/test_scp.rb
208
+ - test/test_strict.rb
209
+ - test/test_various.rb
210
+ - test/test_writer.rb
68
211
  - test/tests.rb
69
- - LICENSE
70
- - README.md
212
+ - test/tests_mimic.rb
213
+ - test/tests_mimic_addition.rb
71
214
  homepage: http://www.ohler.com/oj
72
- licenses: []
215
+ licenses:
216
+ - MIT
217
+ metadata: {}
73
218
  post_install_message:
74
219
  rdoc_options:
75
- - --main
220
+ - "--title"
221
+ - Oj
222
+ - "--main"
76
223
  - README.md
77
224
  require_paths:
78
225
  - lib
79
- - ext
80
226
  required_ruby_version: !ruby/object:Gem::Requirement
81
- none: false
82
227
  requirements:
83
- - - ! '>='
228
+ - - ">="
84
229
  - !ruby/object:Gem::Version
85
230
  version: '0'
86
231
  required_rubygems_version: !ruby/object:Gem::Requirement
87
- none: false
88
232
  requirements:
89
- - - ! '>='
233
+ - - ">="
90
234
  - !ruby/object:Gem::Version
91
235
  version: '0'
92
236
  requirements: []
93
237
  rubyforge_project: oj
94
- rubygems_version: 1.8.23
238
+ rubygems_version: 2.6.11
95
239
  signing_key:
96
- specification_version: 3
240
+ specification_version: 4
97
241
  summary: A fast JSON parser and serializer.
98
- test_files: []
99
- has_rdoc: true
242
+ test_files:
243
+ - test/_test_active.rb
244
+ - test/_test_active_mimic.rb
245
+ - test/_test_mimic_rails.rb
246
+ - test/activesupport4/decoding_test.rb
247
+ - test/activesupport4/encoding_test.rb
248
+ - test/activesupport4/test_helper.rb
249
+ - test/activesupport5/decoding_test.rb
250
+ - test/activesupport5/encoding_test.rb
251
+ - test/activesupport5/encoding_test_cases.rb
252
+ - test/activesupport5/test_helper.rb
253
+ - test/activesupport5/time_zone_test_helpers.rb
254
+ - test/files.rb
255
+ - test/helper.rb
256
+ - test/isolated/shared.rb
257
+ - test/isolated/test_mimic_after.rb
258
+ - test/isolated/test_mimic_alone.rb
259
+ - test/isolated/test_mimic_as_json.rb
260
+ - test/isolated/test_mimic_before.rb
261
+ - test/isolated/test_mimic_define.rb
262
+ - test/isolated/test_mimic_rails_after.rb
263
+ - test/isolated/test_mimic_rails_before.rb
264
+ - test/isolated/test_mimic_redefine.rb
265
+ - test/json_gem/json_addition_test.rb
266
+ - test/json_gem/json_common_interface_test.rb
267
+ - test/json_gem/json_encoding_test.rb
268
+ - test/json_gem/json_ext_parser_test.rb
269
+ - test/json_gem/json_fixtures_test.rb
270
+ - test/json_gem/json_generator_test.rb
271
+ - test/json_gem/json_generic_object_test.rb
272
+ - test/json_gem/json_parser_test.rb
273
+ - test/json_gem/json_string_matching_test.rb
274
+ - test/json_gem/test_helper.rb
275
+ - test/perf.rb
276
+ - test/perf_compat.rb
277
+ - test/perf_fast.rb
278
+ - test/perf_file.rb
279
+ - test/perf_object.rb
280
+ - test/perf_saj.rb
281
+ - test/perf_scp.rb
282
+ - test/perf_simple.rb
283
+ - test/perf_strict.rb
284
+ - test/sample/change.rb
285
+ - test/sample/dir.rb
286
+ - test/sample/doc.rb
287
+ - test/sample/file.rb
288
+ - test/sample/group.rb
289
+ - test/sample/hasprops.rb
290
+ - test/sample/layer.rb
291
+ - test/sample/line.rb
292
+ - test/sample/oval.rb
293
+ - test/sample/rect.rb
294
+ - test/sample/shape.rb
295
+ - test/sample/text.rb
296
+ - test/sample.rb
297
+ - test/sample_json.rb
298
+ - test/test_compat.rb
299
+ - test/test_custom.rb
300
+ - test/test_debian.rb
301
+ - test/test_fast.rb
302
+ - test/test_file.rb
303
+ - test/test_gc.rb
304
+ - test/test_hash.rb
305
+ - test/test_null.rb
306
+ - test/test_object.rb
307
+ - test/test_saj.rb
308
+ - test/test_scp.rb
309
+ - test/test_strict.rb
310
+ - test/test_various.rb
311
+ - test/test_writer.rb
312
+ - test/tests.rb
313
+ - test/tests_mimic.rb
314
+ - test/tests_mimic_addition.rb
data/ext/oj/cache.c DELETED
@@ -1,148 +0,0 @@
1
- /* cache.c
2
- * Copyright (c) 2011, Peter Ohler
3
- * All rights reserved.
4
- *
5
- * Redistribution and use in source and binary forms, with or without
6
- * modification, are permitted provided that the following conditions are met:
7
- *
8
- * - Redistributions of source code must retain the above copyright notice, this
9
- * list of conditions and the following disclaimer.
10
- *
11
- * - Redistributions in binary form must reproduce the above copyright notice,
12
- * this list of conditions and the following disclaimer in the documentation
13
- * and/or other materials provided with the distribution.
14
- *
15
- * - Neither the name of Peter Ohler nor the names of its contributors may be
16
- * used to endorse or promote products derived from this software without
17
- * specific prior written permission.
18
- *
19
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
- */
30
-
31
- #include <stdlib.h>
32
- #include <errno.h>
33
- #include <stdio.h>
34
- #include <string.h>
35
- #include <stdarg.h>
36
-
37
- #include "cache.h"
38
-
39
- struct _Cache {
40
- char *key; // only set if the node has a value, and it is not an exact match
41
- VALUE value;
42
- struct _Cache *slots[16];
43
- };
44
-
45
- static void slot_print(Cache cache, unsigned int depth);
46
-
47
- void
48
- oj_cache_new(Cache *cache) {
49
- if (0 == (*cache = ALLOC(struct _Cache))) {
50
- rb_raise(rb_eNoMemError, "not enough memory\n");
51
- }
52
- (*cache)->key = 0;
53
- (*cache)->value = Qundef;
54
- memset((*cache)->slots, 0, sizeof((*cache)->slots));
55
- }
56
-
57
- VALUE
58
- oj_cache_get(Cache cache, const char *key, VALUE **slot) {
59
- unsigned char *k = (unsigned char*)key;
60
- Cache *cp;
61
-
62
- for (; '\0' != *k; k++) {
63
- cp = cache->slots + (unsigned int)(*k >> 4); // upper 4 bits
64
- if (0 == *cp) {
65
- oj_cache_new(cp);
66
- }
67
- cache = *cp;
68
- cp = cache->slots + (unsigned int)(*k & 0x0F); // lower 4 bits
69
- if (0 == *cp) {
70
- oj_cache_new(cp);
71
- cache = *cp;
72
- cache->key = ('\0' == *(k + 1)) ? 0 : strdup(key);
73
- break;
74
- } else {
75
- cache = *cp;
76
- if (Qundef != cache->value && 0 != cache->key) {
77
- unsigned char *ck = (unsigned char*)(cache->key + (unsigned int)(k - (unsigned char*)key + 1));
78
-
79
- if (0 == strcmp((char*)ck, (char*)(k + 1))) {
80
- break;
81
- } else {
82
- Cache *cp2 = cp;
83
-
84
- // if value was set along with the key then there are no slots filled yet
85
- cp2 = (*cp2)->slots + (*ck >> 4);
86
- oj_cache_new(cp2);
87
- cp2 = (*cp2)->slots + (*ck & 0x0F);
88
- oj_cache_new(cp2);
89
- if ('\0' == *(ck + 1)) {
90
- xfree(cache->key);
91
- } else {
92
- (*cp2)->key = cache->key;
93
- }
94
- (*cp2)->value = cache->value;
95
- cache->key = 0;
96
- cache->value = Qundef;
97
- }
98
- }
99
- }
100
- }
101
- *slot = &cache->value;
102
-
103
- return cache->value;
104
- }
105
-
106
- void
107
- oj_cache_print(Cache cache) {
108
- //printf("-------------------------------------------\n");
109
- slot_print(cache, 0);
110
- }
111
-
112
- static void
113
- slot_print(Cache c, unsigned int depth) {
114
- char indent[256];
115
- Cache *cp;
116
- unsigned int i;
117
-
118
- if (sizeof(indent) - 1 < depth) {
119
- depth = ((int)sizeof(indent) - 1);
120
- }
121
- memset(indent, ' ', depth);
122
- indent[depth] = '\0';
123
- for (i = 0, cp = c->slots; i < 16; i++, cp++) {
124
- if (0 == *cp) {
125
- //printf("%s%02u:\n", indent, i);
126
- } else {
127
- if (0 == (*cp)->key && Qundef == (*cp)->value) {
128
- printf("%s%02u:\n", indent, i);
129
- } else {
130
- const char *key = (0 == (*cp)->key) ? "*" : (*cp)->key;
131
- const char *vs;
132
- const char *clas;
133
-
134
- if (Qundef == (*cp)->value) {
135
- vs = "undefined";
136
- clas = "";
137
- } else {
138
- VALUE rs = rb_funcall2((*cp)->value, rb_intern("to_s"), 0, 0);
139
-
140
- vs = StringValuePtr(rs);
141
- clas = rb_class2name(rb_obj_class((*cp)->value));
142
- }
143
- printf("%s%02u: %s = %s (%s)\n", indent, i, key, vs, clas);
144
- }
145
- slot_print(*cp, depth + 2);
146
- }
147
- }
148
- }
data/ext/oj/foo.rb DELETED
@@ -1,6 +0,0 @@
1
-
2
- def foo()
3
- [1, [true, false]].each { |x| yield x }
4
- end
5
-
6
- foo() { |x| puts x }