<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
path: root/walk
diff options
context:
space:
mode:
Diffstat (limited to 'walk')
-rw-r--r--walk/read.go69
1 files changed, 28 insertions, 41 deletions
diff --git a/walk/read.go b/walk/read.go
index e46ae58..e1b33a4 100644
--- a/walk/read.go
+++ b/walk/read.go
@@ -141,8 +141,33 @@ func firstValue(atoms []Atom) ([]Atom, bool) {
}
}
+func (in *JSONIn) readValue() []Atom {
+ try:
+ value, incomplete := firstValue(in.readBuffer[in.readIndex:])
+ if incomplete {
+ if in.readIndex == 0 {
+ newReadBuffer := make([]Atom, len(in.readBuffer), in.readBufferCapacity * 2)
+ in.readBufferCapacity *= 2
+ copy(newReadBuffer, in.readBuffer)
+ in.readBuffer = newReadBuffer
+ in.fillReadBuffer()
+ goto try
+ }
+ copy(in.readBuffer, in.readBuffer[in.readIndex:])
+ in.readBuffer = in.readBuffer[:len(in.readBuffer) - in.readIndex]
+ in.readIndex = 0
+ copy(in.actionBuffer, in.actionBuffer[in.actionIndex:])
+ in.actionBuffer = in.actionBuffer[:len(in.actionBuffer) - in.actionIndex]
+ in.actionIndex = 0
+ in.fillReadBuffer()
+ goto try
+ }
+ in.readIndex += len(value)
+ return value
+}
+
func (in *JSONIn) Read() (WalkItem, error) {
- actionLoop: for {
+ for {
if in.actionIndex == len(in.actionBuffer) {
in.actionIndex = 0
in.readIndex = 0
@@ -156,52 +181,14 @@ func (in *JSONIn) Read() (WalkItem, error) {
action := in.actionBuffer[in.actionIndex]
switch action {
case ActionReadValue:
- value, incomplete := firstValue(in.readBuffer[in.readIndex:])
- if incomplete {
- if in.readIndex == 0 {
- newReadBuffer := make([]Atom, len(in.readBuffer), in.readBufferCapacity * 2)
- in.readBufferCapacity *= 2
- copy(newReadBuffer, in.readBuffer)
- in.readBuffer = newReadBuffer
- in.fillReadBuffer()
- continue actionLoop
- }
- copy(in.readBuffer, in.readBuffer[in.readIndex:])
- in.readBuffer = in.readBuffer[:len(in.readBuffer) - in.readIndex]
- in.readIndex = 0
- copy(in.actionBuffer, in.actionBuffer[in.actionIndex:])
- in.actionBuffer = in.actionBuffer[:len(in.actionBuffer) - in.actionIndex]
- in.actionIndex = 0
- in.fillReadBuffer()
- continue actionLoop
- }
- in.readIndex += len(value)
+ value := in.readValue()
in.actionIndex++
return WalkItem {
Value: value,
Path: in.path,
}, nil
case ActionAppendPath:
- value, incomplete := firstValue(in.readBuffer[in.readIndex:])
- if incomplete {
- if in.readIndex == 0 {
- newReadBuffer := make([]Atom, len(in.readBuffer), in.readBufferCapacity * 2)
- in.readBufferCapacity *= 2
- copy(newReadBuffer, in.readBuffer)
- in.readBuffer = newReadBuffer
- in.fillReadBuffer()
- continue actionLoop
- }
- copy(in.readBuffer, in.readBuffer[in.readIndex:])
- in.readBuffer = in.readBuffer[:len(in.readBuffer) - in.readIndex]
- in.readIndex = 0
- copy(in.actionBuffer, in.actionBuffer[in.actionIndex:])
- in.actionBuffer = in.actionBuffer[:len(in.actionBuffer) - in.actionIndex]
- in.actionIndex = 0
- in.fillReadBuffer()
- continue actionLoop
- }
- in.readIndex += len(value)
+ value := in.readValue()
in.path = append(in.path, value...)
case ActionAppendPathNull:
in.path = append(in.path, NewAtomNull())