Skip to content

Commit 21eef55

Browse files
TkTechlemire
authored andcommitted
Changes to the behaviour of move_forward to make it suitable for iteration. (Closes simdjson#73) (simdjson#103)
1 parent d5a35c8 commit 21eef55

1 file changed

Lines changed: 18 additions & 19 deletions

File tree

src/parsedjsoniterator.cpp

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -73,31 +73,30 @@ uint8_t ParsedJson::iterator::get_scope_type() const {
7373
}
7474

7575
bool ParsedJson::iterator::move_forward() {
76-
if(location + 1 >= tape_length) {
77-
return false; // we are at the end!
78-
}
79-
// we are entering a new scope
80-
if ((current_type == '[') || (current_type == '{')){
81-
depth++;
82-
depthindex[depth].start_of_scope = location;
83-
depthindex[depth].scope_type = current_type;
84-
}
85-
location = location + 1;
86-
current_val = pj.tape[location];
87-
current_type = (current_val >> 56);
88-
// if we encounter a scope closure, we need to move up
89-
while ((current_type == ']') || (current_type == '}')) {
9076
if(location + 1 >= tape_length) {
9177
return false; // we are at the end!
9278
}
93-
depth--;
94-
if(depth == 0) {
95-
return false; // should not be necessary
79+
80+
if ((current_type == '[') || (current_type == '{')){
81+
// We are entering a new scope
82+
depth++;
83+
depthindex[depth].start_of_scope = location;
84+
depthindex[depth].scope_type = current_type;
85+
} else if ((current_type == ']') || (current_type == '}')) {
86+
// Leaving a scope.
87+
depth--;
88+
if(depth == 0) {
89+
// Should not be necessary
90+
return false;
91+
}
92+
} else if ((current_type == 'd') || (current_type == 'l')) {
93+
// d and l types use 2 locations on the tape, not just one.
94+
location += 1;
9695
}
97-
location = location + 1;
96+
97+
location += 1;
9898
current_val = pj.tape[location];
9999
current_type = (current_val >> 56);
100-
}
101100
return true;
102101
}
103102

0 commit comments

Comments
 (0)