Skip to content

Commit

Permalink
Simplification and introduction of top-level JSON array support.
Browse files Browse the repository at this point in the history
Closes #10
  • Loading branch information
ateska committed Apr 6, 2021
1 parent 00fbdb5 commit 3305336
Show file tree
Hide file tree
Showing 8 changed files with 184 additions and 202 deletions.
241 changes: 166 additions & 75 deletions cysimdjson/cysimdjson.pyx

Large diffs are not rendered by default.

15 changes: 4 additions & 11 deletions cysimdjson/jsoninter.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,9 @@

using namespace simdjson;

// To avoid naming collisions between dom::object and python namespace
using simdjson_object = dom::object;
using simdjson_element_type = dom::element_type;
using simdjson_element = dom::element;
using simdjson_array = dom::array;
using simdjson_parser = dom::parser;


inline int getitem_from_element(dom::element & element, const std::string & key, dom::element & value) {
auto error = element[key].get(value);
inline int getitem_from_object(dom::object & obj, const std::string & key, dom::element & value) {
auto error = obj[key].get(value);
if (error) {
return -1;
}
Expand All @@ -30,8 +23,8 @@ inline int getitem_from_array(dom::array & array, int key, dom::element & value)
}


inline int at_pointer_element(dom::element & element, std::string & key, dom::element & value) {
auto error = element.at_pointer(key).get(value);
inline int at_pointer_object(dom::object & obj, std::string & key, dom::element & value) {
auto error = obj.at_pointer(key).get(value);
if (error) {
return -1;
}
Expand Down
3 changes: 0 additions & 3 deletions cysimdjson/ondemand/README.md

This file was deleted.

26 changes: 0 additions & 26 deletions cysimdjson/ondemand/jsoninter.h

This file was deleted.

85 changes: 0 additions & 85 deletions cysimdjson/ondemand/simdjsonpy.pyx

This file was deleted.

3 changes: 1 addition & 2 deletions cysimdjson/pysimdjson/errors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
*
* simd_element at(int) except +simdjson_error_handler
*/
void
simdjson_error_handler() {
void simdjson_error_handler() {
using namespace simdjson;

try {
Expand Down
12 changes: 12 additions & 0 deletions test/test_array/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

class JSONArrayTestCases(unittest.TestCase):


def test_iter_01(self):

parser = cysimdjson.JSONParser()
Expand All @@ -19,3 +20,14 @@ def test_iter_01(self):
self.assertEqual(len(ar), 10)
for i, n in enumerate(ar, 1):
self.assertEqual(i, n)


def test_iter_02(self):

parser = cysimdjson.JSONParser()

with open(os.path.join(THIS_DIR, 'top_array.json'), 'rb') as fo:
json_parsed = parser.parse(fo.read())

for i, n in enumerate(json_parsed, 1):
self.assertEqual(i, n)
1 change: 1 addition & 0 deletions test/test_array/top_array.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

0 comments on commit 3305336

Please sign in to comment.