Browse Source

bump buntdb to v1.2.3

Potentially fixes the database corruption seen on #1603
tags/v2.6.0-rc1
Shivaram Lingamneni 3 years ago
parent
commit
fd3cbab6ee
36 changed files with 912 additions and 324 deletions
  1. 2
    1
      go.mod
  2. 17
    0
      go.sum
  3. 0
    1
      vendor/github.com/tidwall/btree/.travis.yml
  4. 196
    2
      vendor/github.com/tidwall/btree/README.md
  5. 175
    87
      vendor/github.com/tidwall/btree/btree.go
  6. 0
    4
      vendor/github.com/tidwall/buntdb/.travis.yml
  7. 2
    3
      vendor/github.com/tidwall/buntdb/README.md
  8. 95
    47
      vendor/github.com/tidwall/buntdb/buntdb.go
  9. 7
    7
      vendor/github.com/tidwall/buntdb/go.mod
  10. 16
    14
      vendor/github.com/tidwall/buntdb/go.sum
  11. 0
    1
      vendor/github.com/tidwall/gjson/.travis.yml
  12. 4
    13
      vendor/github.com/tidwall/gjson/README.md
  13. 12
    3
      vendor/github.com/tidwall/gjson/SYNTAX.md
  14. 131
    89
      vendor/github.com/tidwall/gjson/gjson.go
  15. 2
    2
      vendor/github.com/tidwall/gjson/go.mod
  16. 4
    4
      vendor/github.com/tidwall/gjson/go.sum
  17. 5
    0
      vendor/github.com/tidwall/grect/go.mod
  18. 6
    0
      vendor/github.com/tidwall/grect/go.sum
  19. 0
    1
      vendor/github.com/tidwall/match/.travis.yml
  20. 9
    12
      vendor/github.com/tidwall/match/README.md
  21. 3
    0
      vendor/github.com/tidwall/match/go.mod
  22. 16
    5
      vendor/github.com/tidwall/match/match.go
  23. 0
    1
      vendor/github.com/tidwall/pretty/.travis.yml
  24. 40
    3
      vendor/github.com/tidwall/pretty/README.md
  25. 147
    11
      vendor/github.com/tidwall/pretty/pretty.go
  26. 0
    0
      vendor/github.com/tidwall/rtred/LICENSE
  27. 0
    1
      vendor/github.com/tidwall/rtred/README.md
  28. 0
    0
      vendor/github.com/tidwall/rtred/base/knn.go
  29. 0
    0
      vendor/github.com/tidwall/rtred/base/load.go
  30. 0
    0
      vendor/github.com/tidwall/rtred/base/rtree.go
  31. 5
    0
      vendor/github.com/tidwall/rtred/go.mod
  32. 2
    0
      vendor/github.com/tidwall/rtred/go.sum
  33. 2
    2
      vendor/github.com/tidwall/rtred/rtree.go
  34. 0
    1
      vendor/github.com/tidwall/rtree/.travis.yml
  35. 3
    0
      vendor/github.com/tidwall/tinyqueue/go.mod
  36. 11
    9
      vendor/modules.txt

+ 2
- 1
go.mod View File

@@ -16,7 +16,8 @@ require (
16 16
 	github.com/oragono/confusables v0.0.0-20201108231250-4ab98ab61fb1
17 17
 	github.com/oragono/go-ident v0.0.0-20200511222032-830550b1d775
18 18
 	github.com/stretchr/testify v1.4.0 // indirect
19
-	github.com/tidwall/buntdb v1.1.4
19
+	github.com/tidwall/buntdb v1.2.3
20
+	github.com/tidwall/rtree v0.0.0-20201027154624-32188eeb08a8 // indirect
20 21
 	github.com/toorop/go-dkim v0.0.0-20201103131630-e1cd1a0a5208
21 22
 	golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897
22 23
 	golang.org/x/sys v0.0.0-20201107080550-4d91cf3a1aaf // indirect

+ 17
- 0
go.sum View File

@@ -67,20 +67,37 @@ github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJy
67 67
 github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
68 68
 github.com/tidwall/btree v0.2.2 h1:VVo0JW/tdidNdQzNsDR4wMbL3heaxA1DGleyzQ3/niY=
69 69
 github.com/tidwall/btree v0.2.2/go.mod h1:huei1BkDWJ3/sLXmO+bsCNELL+Bp2Kks9OLyQFkzvA8=
70
+github.com/tidwall/btree v0.4.2 h1:aLwwJlG+InuFzdAPuBf9YCAR1LvSQ9zhC5aorFPlIPs=
71
+github.com/tidwall/btree v0.4.2/go.mod h1:huei1BkDWJ3/sLXmO+bsCNELL+Bp2Kks9OLyQFkzvA8=
70 72
 github.com/tidwall/buntdb v1.1.4 h1:W7y9+2dM3GOswU0t3pz6+BcwZXjj/tVOhPcO6EHufME=
71 73
 github.com/tidwall/buntdb v1.1.4/go.mod h1:06+/n7EFf6uUaIG5r9xZcExYN3H0Lnc+g/Kqx0fZFkI=
74
+github.com/tidwall/buntdb v1.2.3 h1:AoGVe4yrhKmnEPHrPrW5EUOATHOCIk4VtFvd8xn/ZtU=
75
+github.com/tidwall/buntdb v1.2.3/go.mod h1:+i/gBwYOHWG19wLgwMXFLkl00twh9+VWkkaOhuNQ4PA=
72 76
 github.com/tidwall/gjson v1.6.1 h1:LRbvNuNuvAiISWg6gxLEFuCe72UKy5hDqhxW/8183ws=
73 77
 github.com/tidwall/gjson v1.6.1/go.mod h1:BaHyNc5bjzYkPqgLq7mdVzeiRtULKULXLgZFKsxEHI0=
78
+github.com/tidwall/gjson v1.7.4 h1:19cchw8FOxkG5mdLRkGf9jqIqEyqdZhPqW60XfyFxk8=
79
+github.com/tidwall/gjson v1.7.4/go.mod h1:5/xDoumyyDNerp2U36lyolv46b3uF/9Bu6OfyQ9GImk=
74 80
 github.com/tidwall/grect v0.0.0-20161006141115-ba9a043346eb h1:5NSYaAdrnblKByzd7XByQEJVT8+9v0W/tIY0Oo4OwrE=
75 81
 github.com/tidwall/grect v0.0.0-20161006141115-ba9a043346eb/go.mod h1:lKYYLFIr9OIgdgrtgkZ9zgRxRdvPYsExnYBsEAd8W5M=
82
+github.com/tidwall/grect v0.1.1 h1:+kMEkxhoqB7rniVXzMEIA66XwU07STgINqxh+qVIndY=
83
+github.com/tidwall/grect v0.1.1/go.mod h1:CzvbGiFbWUwiJ1JohXLb28McpyBsI00TK9Y6pDWLGRQ=
84
+github.com/tidwall/lotsa v1.0.2/go.mod h1:X6NiU+4yHA3fE3Puvpnn1XMDrFZrE9JO2/w+UMuqgR8=
76 85
 github.com/tidwall/match v1.0.1 h1:PnKP62LPNxHKTwvHHZZzdOAOCtsJTjo6dZLCwpKm5xc=
77 86
 github.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E=
87
+github.com/tidwall/match v1.0.3 h1:FQUVvBImDutD8wJLN6c5eMzWtjgONK9MwIBCOrUJKeE=
88
+github.com/tidwall/match v1.0.3/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
78 89
 github.com/tidwall/pretty v1.0.2 h1:Z7S3cePv9Jwm1KwS0513MRaoUe3S01WPbLNV40pwWZU=
79 90
 github.com/tidwall/pretty v1.0.2/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
91
+github.com/tidwall/pretty v1.1.0 h1:K3hMW5epkdAVwibsQEfR/7Zj0Qgt4DxtNumTq/VloO8=
92
+github.com/tidwall/pretty v1.1.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
93
+github.com/tidwall/rtred v0.1.2 h1:exmoQtOLvDoO8ud++6LwVsAMTu0KPzLTUrMln8u1yu8=
94
+github.com/tidwall/rtred v0.1.2/go.mod h1:hd69WNXQ5RP9vHd7dqekAz+RIdtfBogmglkZSRxCHFQ=
80 95
 github.com/tidwall/rtree v0.0.0-20201027154624-32188eeb08a8 h1:BsKSRhu0TDB6Snq8SutN9KQHc6vqHEXJTcAFwyGNius=
81 96
 github.com/tidwall/rtree v0.0.0-20201027154624-32188eeb08a8/go.mod h1:/h+UnNGt0IhNNJLkGikcdcJqm66zGD/uJGMRxK/9+Ao=
82 97
 github.com/tidwall/tinyqueue v0.0.0-20180302190814-1e39f5511563 h1:Otn9S136ELckZ3KKDyCkxapfufrqDqwmGjcHfAyXRrE=
83 98
 github.com/tidwall/tinyqueue v0.0.0-20180302190814-1e39f5511563/go.mod h1:mLqSmt7Dv/CNneF2wfcChfN1rvapyQr01LGKnKex0DQ=
99
+github.com/tidwall/tinyqueue v0.1.1 h1:SpNEvEggbpyN5DIReaJ2/1ndroY8iyEGxPYxoSaymYE=
100
+github.com/tidwall/tinyqueue v0.1.1/go.mod h1:O/QNHwrnjqr6IHItYrzoHAKYhBkLI67Q096fQP5zMYw=
84 101
 github.com/toorop/go-dkim v0.0.0-20201103131630-e1cd1a0a5208 h1:PM5hJF7HVfNWmCjMdEfbuOBNXSVF2cMFGgQTPdKCbwM=
85 102
 github.com/toorop/go-dkim v0.0.0-20201103131630-e1cd1a0a5208/go.mod h1:BzWtXXrXzZUvMacR0oF/fbDDgUPO8L36tDMmRAf14ns=
86 103
 golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=

+ 0
- 1
vendor/github.com/tidwall/btree/.travis.yml View File

@@ -1 +0,0 @@
1
-language: go

+ 196
- 2
vendor/github.com/tidwall/btree/README.md View File

@@ -1,5 +1,199 @@
1
-# B-tree for Go
1
+# btree
2 2
 
3
-![Travis CI Build Status](https://api.travis-ci.org/tidwall/btree.svg?branch=master)
4 3
 [![GoDoc](https://godoc.org/github.com/tidwall/btree?status.svg)](https://godoc.org/github.com/tidwall/btree)
5 4
 
5
+An [efficient](#performance) [B-tree](https://en.wikipedia.org/wiki/B-tree) implementation in Go. 
6
+
7
+## Features
8
+
9
+- `Copy()` method with copy-on-write support.
10
+- Fast bulk loading for pre-ordered data using the `Load()` method.
11
+- All operations are thread-safe.
12
+- Path hinting optimization for operations with nearby keys.
13
+
14
+## Installing
15
+
16
+To start using btree, install Go and run `go get`:
17
+
18
+```sh
19
+$ go get -u github.com/tidwall/btree
20
+```
21
+
22
+## Usage
23
+
24
+```go
25
+package main
26
+
27
+import (
28
+	"fmt"
29
+
30
+	"github.com/tidwall/btree"
31
+)
32
+
33
+type Item struct {
34
+	Key, Val string
35
+}
36
+
37
+// byKeys is a comparison function that compares item keys and returns true
38
+// when a is less than b.
39
+func byKeys(a, b interface{}) bool {
40
+	i1, i2 := a.(*Item), b.(*Item)
41
+	return i1.Key < i2.Key
42
+}
43
+
44
+// byVals is a comparison function that compares item values and returns true
45
+// when a is less than b.
46
+func byVals(a, b interface{}) bool {
47
+	i1, i2 := a.(*Item), b.(*Item)
48
+	if i1.Val < i2.Val {
49
+		return true
50
+	}
51
+	if i1.Val > i2.Val {
52
+		return false
53
+	}
54
+	// Both vals are equal so we should fall though
55
+	// and let the key comparison take over.
56
+	return byKeys(a, b)
57
+}
58
+
59
+func main() {
60
+	// Create a tree for keys and a tree for values.
61
+	// The "keys" tree will be sorted on the Keys field.
62
+	// The "values" tree will be sorted on the Values field.
63
+	keys := btree.New(byKeys)
64
+	vals := btree.New(byVals)
65
+
66
+	// Create some items.
67
+	users := []*Item{
68
+		&Item{Key: "user:1", Val: "Jane"},
69
+		&Item{Key: "user:2", Val: "Andy"},
70
+		&Item{Key: "user:3", Val: "Steve"},
71
+		&Item{Key: "user:4", Val: "Andrea"},
72
+		&Item{Key: "user:5", Val: "Janet"},
73
+		&Item{Key: "user:6", Val: "Andy"},
74
+	}
75
+
76
+	// Insert each user into both trees
77
+	for _, user := range users {
78
+		keys.Set(user)
79
+		vals.Set(user)
80
+	}
81
+
82
+	// Iterate over each user in the key tree
83
+	keys.Ascend(nil, func(item interface{}) bool {
84
+		kvi := item.(*Item)
85
+		fmt.Printf("%s %s\n", kvi.Key, kvi.Val)
86
+		return true
87
+	})
88
+
89
+	fmt.Printf("\n")
90
+	// Iterate over each user in the val tree
91
+	vals.Ascend(nil, func(item interface{}) bool {
92
+		kvi := item.(*Item)
93
+		fmt.Printf("%s %s\n", kvi.Key, kvi.Val)
94
+		return true
95
+	})
96
+
97
+	// Output:
98
+	// user:1 Jane
99
+	// user:2 Andy
100
+	// user:3 Steve
101
+	// user:4 Andrea
102
+	// user:5 Janet
103
+	// user:6 Andy
104
+	//
105
+	// user:4 Andrea
106
+	// user:2 Andy
107
+	// user:6 Andy
108
+	// user:1 Jane
109
+	// user:5 Janet
110
+	// user:3 Steve
111
+}
112
+```
113
+
114
+## Operations
115
+
116
+### Basic
117
+
118
+```
119
+Len()                   # return the number of items in the btree
120
+Set(item)               # insert or replace an existing item
121
+Get(item)               # get an existing item
122
+Delete(item)            # delete an item
123
+```
124
+
125
+### Iteration
126
+
127
+```
128
+Ascend(pivot, iter)     # scan items in ascending order starting at pivot.
129
+Descend(pivot, iter)    # scan items in descending order starting at pivot.
130
+```
131
+
132
+### Queues
133
+
134
+```
135
+Min()                   # return the first item in the btree
136
+Max()                   # return the last item in the btree
137
+PopMin()                # remove and return the first item in the btree
138
+PopMax()                # remove and return the last item in the btree
139
+```
140
+### Bulk loading
141
+
142
+```
143
+Load(item)              # load presorted items into tree
144
+```
145
+
146
+### Path hints
147
+
148
+```
149
+SetHint(item, *hint)    # insert or replace an existing item
150
+GetHint(item, *hint)    # get an existing item
151
+DeleteHint(item, *hint) # delete an item
152
+```
153
+
154
+## Performance
155
+
156
+This implementation was designed with performance in mind. 
157
+
158
+The following benchmarks were run on my 2019 Macbook Pro (2.4 GHz 8-Core Intel Core i9) using Go 1.15.3. The items are simple 8-byte ints. 
159
+
160
+- `google`: The [google/btree](https://github.com/google/btree) package
161
+- `tidwall`: The [tidwall/btree](https://github.com/tidwall/btree) package
162
+- `go-arr`: Just a simple Go array
163
+
164
+```
165
+** sequential set **
166
+google:  set-seq        1,000,000 ops in 160ms, 6,262,097/sec, 159 ns/op, 31.0 MB, 32 bytes/op
167
+tidwall: set-seq        1,000,000 ops in 142ms, 7,020,721/sec, 142 ns/op, 36.6 MB, 38 bytes/op
168
+tidwall: set-seq-hint   1,000,000 ops in 87ms, 11,503,315/sec, 86 ns/op, 36.6 MB, 38 bytes/op
169
+tidwall: load-seq       1,000,000 ops in 37ms, 27,177,242/sec, 36 ns/op, 36.6 MB, 38 bytes/op
170
+go-arr:  append         1,000,000 ops in 49ms, 20,574,760/sec, 48 ns/op
171
+
172
+** random set **
173
+google:  set-rand       1,000,000 ops in 606ms, 1,649,921/sec, 606 ns/op, 21.5 MB, 22 bytes/op
174
+tidwall: set-rand       1,000,000 ops in 543ms, 1,841,590/sec, 543 ns/op, 26.7 MB, 27 bytes/op
175
+tidwall: set-rand-hint  1,000,000 ops in 573ms, 1,745,624/sec, 572 ns/op, 26.4 MB, 27 bytes/op
176
+tidwall: set-again      1,000,000 ops in 452ms, 2,212,581/sec, 451 ns/op, 27.1 MB, 28 bytes/op
177
+tidwall: set-after-copy 1,000,000 ops in 472ms, 2,117,457/sec, 472 ns/op, 27.9 MB, 29 bytes/op
178
+tidwall: load-rand      1,000,000 ops in 551ms, 1,816,498/sec, 550 ns/op, 26.1 MB, 27 bytes/op
179
+
180
+** sequential get **
181
+google:  get-seq        1,000,000 ops in 133ms, 7,497,604/sec, 133 ns/op
182
+tidwall: get-seq        1,000,000 ops in 110ms, 9,082,972/sec, 110 ns/op
183
+tidwall: get-seq-hint   1,000,000 ops in 55ms, 18,289,945/sec, 54 ns/op
184
+
185
+** random get **
186
+google:  get-rand       1,000,000 ops in 149ms, 6,704,337/sec, 149 ns/op
187
+tidwall: get-rand       1,000,000 ops in 131ms, 7,616,296/sec, 131 ns/op
188
+tidwall: get-rand-hint  1,000,000 ops in 216ms, 4,632,532/sec, 215 ns/op
189
+```
190
+
191
+*You can find the benchmark utility at [tidwall/btree-benchmark](https://github.com/tidwall/btree-benchmark)*
192
+
193
+## Contact
194
+
195
+Josh Baker [@tidwall](http://twitter.com/tidwall)
196
+
197
+## License
198
+
199
+Source code is available under the MIT [License](/LICENSE).

+ 175
- 87
vendor/github.com/tidwall/btree/btree.go View File

@@ -4,35 +4,39 @@
4 4
 
5 5
 package btree
6 6
 
7
+import "sync"
8
+
7 9
 const maxItems = 255
8 10
 const minItems = maxItems * 40 / 100
9 11
 
10
-type node struct {
11
-	leaf     bool
12
-	numItems int16
13
-	items    [maxItems]interface{}
14
-	children *[maxItems + 1]*node
12
+type cow struct {
13
+	_ int // it cannot be an empty struct
15 14
 }
16 15
 
17
-type justaLeaf struct {
16
+type node struct {
17
+	cow      *cow
18 18
 	leaf     bool
19 19
 	numItems int16
20 20
 	items    [maxItems]interface{}
21
+	children *[maxItems + 1]*node
21 22
 }
22 23
 
23 24
 // BTree is an ordered set items
24 25
 type BTree struct {
26
+	mu     *sync.RWMutex
27
+	cow    *cow
25 28
 	root   *node
26 29
 	length int
27 30
 	less   func(a, b interface{}) bool
28 31
 	lnode  *node
29 32
 }
30 33
 
31
-func newNode(leaf bool) *node {
34
+func (tr *BTree) newNode(leaf bool) *node {
32 35
 	n := &node{leaf: leaf}
33 36
 	if !leaf {
34 37
 		n.children = new([maxItems + 1]*node)
35 38
 	}
39
+	n.cow = tr.cow
36 40
 	return n
37 41
 }
38 42
 
@@ -48,6 +52,7 @@ func New(less func(a, b interface{}) bool) *BTree {
48 52
 		panic("nil less")
49 53
 	}
50 54
 	tr := new(BTree)
55
+	tr.mu = new(sync.RWMutex)
51 56
 	tr.less = less
52 57
 	return tr
53 58
 }
@@ -85,8 +90,7 @@ func (n *node) find(key interface{}, less func(a, b interface{}) bool,
85 90
 			high = mid - 1
86 91
 		}
87 92
 	}
88
-	if low > 0 && !less(n.items[low-1], key) &&
89
-		!less(key, n.items[low-1]) {
93
+	if low > 0 && !less(n.items[low-1], key) {
90 94
 		index = low - 1
91 95
 		found = true
92 96
 	} else {
@@ -109,22 +113,29 @@ func (tr *BTree) SetHint(item interface{}, hint *PathHint) (prev interface{}) {
109 113
 	if item == nil {
110 114
 		panic("nil item")
111 115
 	}
116
+	tr.mu.Lock()
117
+	prev = tr.setHint(item, hint)
118
+	tr.mu.Unlock()
119
+	return prev
120
+}
121
+
122
+func (tr *BTree) setHint(item interface{}, hint *PathHint) (prev interface{}) {
112 123
 	if tr.root == nil {
113
-		tr.root = newNode(true)
124
+		tr.root = tr.newNode(true)
114 125
 		tr.root.items[0] = item
115 126
 		tr.root.numItems = 1
116 127
 		tr.length = 1
117 128
 		return
118 129
 	}
119
-	prev = tr.root.set(item, tr.less, hint, 0)
130
+	prev = tr.nodeSet(&tr.root, item, tr.less, hint, 0)
120 131
 	if prev != nil {
121 132
 		return prev
122 133
 	}
123 134
 	tr.lnode = nil
124 135
 	if tr.root.numItems == maxItems {
125
-		n := tr.root
126
-		right, median := n.split()
127
-		tr.root = newNode(false)
136
+		n := tr.cowLoad(&tr.root)
137
+		right, median := tr.nodeSplit(n)
138
+		tr.root = tr.newNode(false)
128 139
 		tr.root.children[0] = n
129 140
 		tr.root.items[0] = median
130 141
 		tr.root.children[1] = right
@@ -139,8 +150,8 @@ func (tr *BTree) Set(item interface{}) (prev interface{}) {
139 150
 	return tr.SetHint(item, nil)
140 151
 }
141 152
 
142
-func (n *node) split() (right *node, median interface{}) {
143
-	right = newNode(n.leaf)
153
+func (tr *BTree) nodeSplit(n *node) (right *node, median interface{}) {
154
+	right = tr.newNode(n.leaf)
144 155
 	median = n.items[maxItems/2]
145 156
 	copy(right.items[:maxItems/2], n.items[maxItems/2+1:])
146 157
 	if !n.leaf {
@@ -159,9 +170,30 @@ func (n *node) split() (right *node, median interface{}) {
159 170
 	return right, median
160 171
 }
161 172
 
162
-func (n *node) set(item interface{}, less func(a, b interface{}) bool,
163
-	hint *PathHint, depth int,
173
+//go:noinline
174
+func (tr *BTree) copy(n *node) *node {
175
+	n2 := *n
176
+	n2.cow = tr.cow
177
+	copy(n2.items[:], n.items[:])
178
+	if n.children != nil {
179
+		n2.children = new([maxItems + 1]*node)
180
+		copy(n2.children[:], n.children[:])
181
+	}
182
+	return &n2
183
+}
184
+
185
+// cowLoad loaded the provide node and, if needed, performs a copy-on-write.
186
+func (tr *BTree) cowLoad(cn **node) *node {
187
+	if (*cn).cow != tr.cow {
188
+		*cn = tr.copy(*cn)
189
+	}
190
+	return *cn
191
+}
192
+
193
+func (tr *BTree) nodeSet(cn **node, item interface{},
194
+	less func(a, b interface{}) bool, hint *PathHint, depth int,
164 195
 ) (prev interface{}) {
196
+	n := tr.cowLoad(cn)
165 197
 	i, found := n.find(item, less, hint, depth)
166 198
 	if found {
167 199
 		prev = n.items[i]
@@ -174,12 +206,12 @@ func (n *node) set(item interface{}, less func(a, b interface{}) bool,
174 206
 		n.numItems++
175 207
 		return nil
176 208
 	}
177
-	prev = n.children[i].set(item, less, hint, depth+1)
209
+	prev = tr.nodeSet(&n.children[i], item, less, hint, depth+1)
178 210
 	if prev != nil {
179 211
 		return prev
180 212
 	}
181 213
 	if n.children[i].numItems == maxItems {
182
-		right, median := n.children[i].split()
214
+		right, median := tr.nodeSplit(n.children[i])
183 215
 		copy(n.children[i+1:], n.children[i:])
184 216
 		copy(n.items[i+1:], n.items[i:])
185 217
 		n.items[i] = median
@@ -216,6 +248,8 @@ func (tr *BTree) Get(key interface{}) interface{} {
216 248
 
217 249
 // GetHint gets a value for key using a path hint
218 250
 func (tr *BTree) GetHint(key interface{}, hint *PathHint) interface{} {
251
+	tr.mu.RLock()
252
+	defer tr.mu.RUnlock()
219 253
 	if tr.root == nil || key == nil {
220 254
 		return nil
221 255
 	}
@@ -246,10 +280,17 @@ func (tr *BTree) Delete(key interface{}) interface{} {
246 280
 
247 281
 // DeleteHint deletes a value for a key using a path hint
248 282
 func (tr *BTree) DeleteHint(key interface{}, hint *PathHint) interface{} {
283
+	tr.mu.Lock()
284
+	prev := tr.deleteHint(key, hint)
285
+	tr.mu.Unlock()
286
+	return prev
287
+}
288
+
289
+func (tr *BTree) deleteHint(key interface{}, hint *PathHint) interface{} {
249 290
 	if tr.root == nil || key == nil {
250 291
 		return nil
251 292
 	}
252
-	prev := tr.root.delete(false, key, tr.less, hint, 0)
293
+	prev := tr.delete(&tr.root, false, key, tr.less, hint, 0)
253 294
 	if prev == nil {
254 295
 		return nil
255 296
 	}
@@ -264,9 +305,10 @@ func (tr *BTree) DeleteHint(key interface{}, hint *PathHint) interface{} {
264 305
 	return prev
265 306
 }
266 307
 
267
-func (n *node) delete(max bool, key interface{},
308
+func (tr *BTree) delete(cn **node, max bool, key interface{},
268 309
 	less func(a, b interface{}) bool, hint *PathHint, depth int,
269 310
 ) interface{} {
311
+	n := tr.cowLoad(cn)
270 312
 	var i int16
271 313
 	var found bool
272 314
 	if max {
@@ -290,74 +332,79 @@ func (n *node) delete(max bool, key interface{},
290 332
 	if found {
291 333
 		if max {
292 334
 			i++
293
-			prev = n.children[i].delete(true, "", less, nil, 0)
335
+			prev = tr.delete(&n.children[i], true, "", less, nil, 0)
294 336
 		} else {
295 337
 			prev = n.items[i]
296
-			maxItem := n.children[i].delete(true, "", less, nil, 0)
338
+			maxItem := tr.delete(&n.children[i], true, "", less, nil, 0)
297 339
 			n.items[i] = maxItem
298 340
 		}
299 341
 	} else {
300
-		prev = n.children[i].delete(max, key, less, hint, depth+1)
342
+		prev = tr.delete(&n.children[i], max, key, less, hint, depth+1)
301 343
 	}
302 344
 	if prev == nil {
303 345
 		return nil
304 346
 	}
305
-	if n.children[i].numItems < minItems {
306
-		if i == n.numItems {
307
-			i--
308
-		}
309
-		if n.children[i].numItems+n.children[i+1].numItems+1 < maxItems {
310
-			// merge left + item + right
311
-			n.children[i].items[n.children[i].numItems] = n.items[i]
312
-			copy(n.children[i].items[n.children[i].numItems+1:],
313
-				n.children[i+1].items[:n.children[i+1].numItems])
314
-			if !n.children[0].leaf {
315
-				copy(n.children[i].children[n.children[i].numItems+1:],
316
-					n.children[i+1].children[:n.children[i+1].numItems+1])
317
-			}
318
-			n.children[i].numItems += n.children[i+1].numItems + 1
319
-			copy(n.items[i:], n.items[i+1:n.numItems])
320
-			copy(n.children[i+1:], n.children[i+2:n.numItems+1])
321
-			n.items[n.numItems] = nil
322
-			n.children[n.numItems+1] = nil
323
-			n.numItems--
324
-		} else if n.children[i].numItems > n.children[i+1].numItems {
325
-			// move left -> right
326
-			copy(n.children[i+1].items[1:],
327
-				n.children[i+1].items[:n.children[i+1].numItems])
328
-			if !n.children[0].leaf {
329
-				copy(n.children[i+1].children[1:],
330
-					n.children[i+1].children[:n.children[i+1].numItems+1])
331
-			}
332
-			n.children[i+1].items[0] = n.items[i]
333
-			if !n.children[0].leaf {
334
-				n.children[i+1].children[0] =
335
-					n.children[i].children[n.children[i].numItems]
336
-			}
337
-			n.children[i+1].numItems++
338
-			n.items[i] = n.children[i].items[n.children[i].numItems-1]
339
-			n.children[i].items[n.children[i].numItems-1] = nil
340
-			if !n.children[0].leaf {
341
-				n.children[i].children[n.children[i].numItems] = nil
342
-			}
343
-			n.children[i].numItems--
344
-		} else {
345
-			// move right -> left
346
-			n.children[i].items[n.children[i].numItems] = n.items[i]
347
-			if !n.children[0].leaf {
348
-				n.children[i].children[n.children[i].numItems+1] =
349
-					n.children[i+1].children[0]
350
-			}
351
-			n.children[i].numItems++
352
-			n.items[i] = n.children[i+1].items[0]
353
-			copy(n.children[i+1].items[:],
354
-				n.children[i+1].items[1:n.children[i+1].numItems])
355
-			if !n.children[0].leaf {
356
-				copy(n.children[i+1].children[:],
357
-					n.children[i+1].children[1:n.children[i+1].numItems+1])
358
-			}
359
-			n.children[i+1].numItems--
347
+	if n.children[i].numItems >= minItems {
348
+		return prev
349
+	}
350
+
351
+	// merge / rebalance nodes
352
+	if i == n.numItems {
353
+		i--
354
+	}
355
+	n.children[i] = tr.cowLoad(&n.children[i])
356
+	n.children[i+1] = tr.cowLoad(&n.children[i+1])
357
+	if n.children[i].numItems+n.children[i+1].numItems+1 < maxItems {
358
+		// merge left + item + right
359
+		n.children[i].items[n.children[i].numItems] = n.items[i]
360
+		copy(n.children[i].items[n.children[i].numItems+1:],
361
+			n.children[i+1].items[:n.children[i+1].numItems])
362
+		if !n.children[0].leaf {
363
+			copy(n.children[i].children[n.children[i].numItems+1:],
364
+				n.children[i+1].children[:n.children[i+1].numItems+1])
365
+		}
366
+		n.children[i].numItems += n.children[i+1].numItems + 1
367
+		copy(n.items[i:], n.items[i+1:n.numItems])
368
+		copy(n.children[i+1:], n.children[i+2:n.numItems+1])
369
+		n.items[n.numItems] = nil
370
+		n.children[n.numItems+1] = nil
371
+		n.numItems--
372
+	} else if n.children[i].numItems > n.children[i+1].numItems {
373
+		// move left -> right
374
+		copy(n.children[i+1].items[1:],
375
+			n.children[i+1].items[:n.children[i+1].numItems])
376
+		if !n.children[0].leaf {
377
+			copy(n.children[i+1].children[1:],
378
+				n.children[i+1].children[:n.children[i+1].numItems+1])
360 379
 		}
380
+		n.children[i+1].items[0] = n.items[i]
381
+		if !n.children[0].leaf {
382
+			n.children[i+1].children[0] =
383
+				n.children[i].children[n.children[i].numItems]
384
+		}
385
+		n.children[i+1].numItems++
386
+		n.items[i] = n.children[i].items[n.children[i].numItems-1]
387
+		n.children[i].items[n.children[i].numItems-1] = nil
388
+		if !n.children[0].leaf {
389
+			n.children[i].children[n.children[i].numItems] = nil
390
+		}
391
+		n.children[i].numItems--
392
+	} else {
393
+		// move right -> left
394
+		n.children[i].items[n.children[i].numItems] = n.items[i]
395
+		if !n.children[0].leaf {
396
+			n.children[i].children[n.children[i].numItems+1] =
397
+				n.children[i+1].children[0]
398
+		}
399
+		n.children[i].numItems++
400
+		n.items[i] = n.children[i+1].items[0]
401
+		copy(n.children[i+1].items[:],
402
+			n.children[i+1].items[1:n.children[i+1].numItems])
403
+		if !n.children[0].leaf {
404
+			copy(n.children[i+1].children[:],
405
+				n.children[i+1].children[1:n.children[i+1].numItems+1])
406
+		}
407
+		n.children[i+1].numItems--
361 408
 	}
362 409
 	return prev
363 410
 }
@@ -366,6 +413,8 @@ func (n *node) delete(max bool, key interface{},
366 413
 // Pass nil for pivot to scan all item in ascending order
367 414
 // Return false to stop iterating
368 415
 func (tr *BTree) Ascend(pivot interface{}, iter func(item interface{}) bool) {
416
+	tr.mu.RLock()
417
+	defer tr.mu.RUnlock()
369 418
 	if tr.root == nil {
370 419
 		return
371 420
 	}
@@ -427,6 +476,8 @@ func (n *node) reverse(iter func(item interface{}) bool) bool {
427 476
 // Pass nil for pivot to scan all item in descending order
428 477
 // Return false to stop iterating
429 478
 func (tr *BTree) Descend(pivot interface{}, iter func(item interface{}) bool) {
479
+	tr.mu.RLock()
480
+	defer tr.mu.RUnlock()
430 481
 	if tr.root == nil {
431 482
 		return
432 483
 	}
@@ -467,6 +518,12 @@ func (tr *BTree) Load(item interface{}) interface{} {
467 518
 	if item == nil {
468 519
 		panic("nil item")
469 520
 	}
521
+	tr.mu.Lock()
522
+	defer tr.mu.Unlock()
523
+
524
+	// Load does not need a cowGrid because the Copy operation sets the
525
+	// lnode to nil.
526
+
470 527
 	if tr.lnode != nil && tr.lnode.numItems < maxItems-2 {
471 528
 		if tr.less(tr.lnode.items[tr.lnode.numItems-1], item) {
472 529
 			tr.lnode.items[tr.lnode.numItems] = item
@@ -475,7 +532,7 @@ func (tr *BTree) Load(item interface{}) interface{} {
475 532
 			return nil
476 533
 		}
477 534
 	}
478
-	prev := tr.Set(item)
535
+	prev := tr.setHint(item, nil)
479 536
 	if prev != nil {
480 537
 		return prev
481 538
 	}
@@ -493,6 +550,8 @@ func (tr *BTree) Load(item interface{}) interface{} {
493 550
 // Min returns the minimum item in tree.
494 551
 // Returns nil if the tree has no items.
495 552
 func (tr *BTree) Min() interface{} {
553
+	tr.mu.RLock()
554
+	defer tr.mu.RUnlock()
496 555
 	if tr.root == nil {
497 556
 		return nil
498 557
 	}
@@ -508,6 +567,8 @@ func (tr *BTree) Min() interface{} {
508 567
 // Max returns the maximum item in tree.
509 568
 // Returns nil if the tree has no items.
510 569
 func (tr *BTree) Max() interface{} {
570
+	tr.mu.RLock()
571
+	defer tr.mu.RUnlock()
511 572
 	if tr.root == nil {
512 573
 		return nil
513 574
 	}
@@ -523,53 +584,65 @@ func (tr *BTree) Max() interface{} {
523 584
 // PopMin removes the minimum item in tree and returns it.
524 585
 // Returns nil if the tree has no items.
525 586
 func (tr *BTree) PopMin() interface{} {
587
+	tr.mu.Lock()
588
+	defer tr.mu.Unlock()
526 589
 	if tr.root == nil {
527 590
 		return nil
528 591
 	}
529 592
 	tr.lnode = nil
530
-	n := tr.root
593
+	n := tr.cowLoad(&tr.root)
531 594
 	for {
532 595
 		if n.leaf {
533 596
 			item := n.items[0]
534 597
 			if n.numItems == minItems {
535
-				return tr.Delete(item)
598
+				return tr.deleteHint(item, nil)
536 599
 			}
537 600
 			copy(n.items[:], n.items[1:])
538 601
 			n.items[n.numItems-1] = nil
539 602
 			n.numItems--
540 603
 			tr.length--
604
+			if tr.length == 0 {
605
+				tr.root = nil
606
+			}
541 607
 			return item
542 608
 		}
543
-		n = n.children[0]
609
+		n = tr.cowLoad(&n.children[0])
544 610
 	}
545 611
 }
546 612
 
547 613
 // PopMax removes the minimum item in tree and returns it.
548 614
 // Returns nil if the tree has no items.
549 615
 func (tr *BTree) PopMax() interface{} {
616
+	tr.mu.Lock()
617
+	defer tr.mu.Unlock()
550 618
 	if tr.root == nil {
551 619
 		return nil
552 620
 	}
553 621
 	tr.lnode = nil
554
-	n := tr.root
622
+	n := tr.cowLoad(&tr.root)
555 623
 	for {
556 624
 		if n.leaf {
557 625
 			item := n.items[n.numItems-1]
558 626
 			if n.numItems == minItems {
559
-				return tr.Delete(item)
627
+				return tr.deleteHint(item, nil)
560 628
 			}
561 629
 			n.items[n.numItems-1] = nil
562 630
 			n.numItems--
563 631
 			tr.length--
632
+			if tr.length == 0 {
633
+				tr.root = nil
634
+			}
564 635
 			return item
565 636
 		}
566
-		n = n.children[n.numItems]
637
+		n = tr.cowLoad(&n.children[n.numItems])
567 638
 	}
568 639
 }
569 640
 
570 641
 // Height returns the height of the tree.
571 642
 // Returns zero if tree has no items.
572 643
 func (tr *BTree) Height() int {
644
+	tr.mu.RLock()
645
+	defer tr.mu.RUnlock()
573 646
 	var height int
574 647
 	if tr.root != nil {
575 648
 		n := tr.root
@@ -587,6 +660,8 @@ func (tr *BTree) Height() int {
587 660
 // Walk iterates over all items in tree, in order.
588 661
 // The items param will contain one or more items.
589 662
 func (tr *BTree) Walk(iter func(item []interface{})) {
663
+	tr.mu.RLock()
664
+	defer tr.mu.RUnlock()
590 665
 	if tr.root != nil {
591 666
 		tr.root.walk(iter)
592 667
 	}
@@ -603,3 +678,16 @@ func (n *node) walk(iter func(item []interface{})) {
603 678
 		n.children[n.numItems].walk(iter)
604 679
 	}
605 680
 }
681
+
682
+// Copy the tree. This operation is very fast because it only performs a
683
+// shadowed copy.
684
+func (tr *BTree) Copy() *BTree {
685
+	tr.mu.Lock()
686
+	tr.lnode = nil
687
+	tr.cow = new(cow)
688
+	tr2 := *tr
689
+	tr2.mu = new(sync.RWMutex)
690
+	tr2.cow = new(cow)
691
+	tr.mu.Unlock()
692
+	return &tr2
693
+}

+ 0
- 4
vendor/github.com/tidwall/buntdb/.travis.yml View File

@@ -1,4 +0,0 @@
1
-language: go
2
-
3
-go:
4
-    - 1.15.x

+ 2
- 3
vendor/github.com/tidwall/buntdb/README.md View File

@@ -3,10 +3,9 @@
3 3
     src="logo.png"
4 4
     width="307" height="150" border="0" alt="BuntDB">
5 5
 <br>
6
-<a href="https://travis-ci.org/tidwall/buntdb"><img src="https://img.shields.io/travis/tidwall/buntdb.svg?style=flat-square" alt="Build Status"></a>
7
-<a href="http://gocover.io/github.com/tidwall/buntdb"><img src="https://img.shields.io/badge/coverage-95%25-brightgreen.svg?style=flat-square" alt="Code Coverage"></a>
8 6
 <a href="https://goreportcard.com/report/github.com/tidwall/buntdb"><img src="https://goreportcard.com/badge/github.com/tidwall/buntdb?style=flat-square" alt="Go Report Card"></a>
9
-<a href="https://godoc.org/github.com/tidwall/buntdb"><img src="https://img.shields.io/badge/api-reference-blue.svg?style=flat-square" alt="GoDoc"></a>
7
+<a href="https://godoc.org/github.com/tidwall/buntdb"><img src="https://img.shields.io/badge/go-documentation-blue.svg?style=flat-square" alt="Godoc"></a>
8
+<a href="https://github.com/tidwall/buntdb/blob/master/LICENSE"><img src="https://img.shields.io/github/license/tidwall/buntdb.svg?style=flat-square" alt="LICENSE"></a>
10 9
 </p>
11 10
 
12 11
 BuntDB is a low-level, in-memory, key/value store in pure Go.

+ 95
- 47
vendor/github.com/tidwall/buntdb/buntdb.go View File

@@ -19,7 +19,7 @@ import (
19 19
 	"github.com/tidwall/gjson"
20 20
 	"github.com/tidwall/grect"
21 21
 	"github.com/tidwall/match"
22
-	"github.com/tidwall/rtree"
22
+	"github.com/tidwall/rtred"
23 23
 )
24 24
 
25 25
 var (
@@ -69,7 +69,6 @@ type DB struct {
69 69
 	keys      *btree.BTree      // a tree of all item ordered by key
70 70
 	exps      *btree.BTree      // a tree of items ordered by expiration
71 71
 	idxs      map[string]*index // the index trees.
72
-	exmgr     bool              // indicates that expires manager is running.
73 72
 	flushes   int               // a count of the number of disk flushes
74 73
 	closed    bool              // set when the database has been closed
75 74
 	config    Config            // the database configuration
@@ -135,9 +134,6 @@ type exctx struct {
135 134
 	db *DB
136 135
 }
137 136
 
138
-// Default number of btree degrees
139
-const btreeDegrees = 64
140
-
141 137
 // Open opens a database at the provided path.
142 138
 // If the file does not exist then it will be created automatically.
143 139
 func Open(path string) (*DB, error) {
@@ -241,14 +237,15 @@ func (db *DB) Load(rd io.Reader) error {
241 237
 		// cannot load into databases that persist to disk
242 238
 		return ErrPersistenceActive
243 239
 	}
244
-	return db.readLoad(rd, time.Now())
240
+	_, err := db.readLoad(rd, time.Now())
241
+	return err
245 242
 }
246 243
 
247 244
 // index represents a b-tree or r-tree index and also acts as the
248 245
 // b-tree/r-tree context for itself.
249 246
 type index struct {
250 247
 	btr     *btree.BTree                           // contains the items
251
-	rtr     *rtree.RTree                           // contains the items
248
+	rtr     *rtred.RTree                           // contains the items
252 249
 	name    string                                 // name of the index
253 250
 	pattern string                                 // a required key pattern
254 251
 	less    func(a, b string) bool                 // less comparison function
@@ -289,7 +286,7 @@ func (idx *index) clearCopy() *index {
289 286
 		nidx.btr = btree.New(lessCtx(nidx))
290 287
 	}
291 288
 	if nidx.rect != nil {
292
-		nidx.rtr = rtree.New(nidx)
289
+		nidx.rtr = rtred.New(nidx)
293 290
 	}
294 291
 	return nidx
295 292
 }
@@ -301,7 +298,7 @@ func (idx *index) rebuild() {
301 298
 		idx.btr = btree.New(lessCtx(idx))
302 299
 	}
303 300
 	if idx.rect != nil {
304
-		idx.rtr = rtree.New(idx)
301
+		idx.rtr = rtred.New(idx)
305 302
 	}
306 303
 	// iterate through all keys and fill the index
307 304
 	btreeAscend(idx.db.keys, func(item interface{}) bool {
@@ -755,46 +752,65 @@ func (db *DB) Shrink() error {
755 752
 	}()
756 753
 }
757 754
 
758
-var errValidEOF = errors.New("valid eof")
759
-
760 755
 // readLoad reads from the reader and loads commands into the database.
761 756
 // modTime is the modified time of the reader, should be no greater than
762 757
 // the current time.Now().
763
-func (db *DB) readLoad(rd io.Reader, modTime time.Time) error {
758
+// Returns the number of bytes of the last command read and the error if any.
759
+func (db *DB) readLoad(rd io.Reader, modTime time.Time) (n int64, err error) {
760
+	defer func() {
761
+		if err == io.EOF {
762
+			err = io.ErrUnexpectedEOF
763
+		}
764
+	}()
765
+	totalSize := int64(0)
764 766
 	data := make([]byte, 4096)
765 767
 	parts := make([]string, 0, 8)
766 768
 	r := bufio.NewReader(rd)
767 769
 	for {
770
+		// peek at the first byte. If it's a 'nul' control character then
771
+		// ignore it and move to the next byte.
772
+		c, err := r.ReadByte()
773
+		if err != nil {
774
+			if err == io.EOF {
775
+				err = nil
776
+			}
777
+			return totalSize, err
778
+		}
779
+		if c == 0 {
780
+			// ignore nul control characters
781
+			n += 1
782
+			continue
783
+		}
784
+		if err := r.UnreadByte(); err != nil {
785
+			return totalSize, err
786
+		}
787
+
768 788
 		// read a single command.
769 789
 		// first we should read the number of parts that the of the command
790
+		cmdByteSize := int64(0)
770 791
 		line, err := r.ReadBytes('\n')
771 792
 		if err != nil {
772
-			if len(line) > 0 {
773
-				// got an eof but also data. this should be an unexpected eof.
774
-				return io.ErrUnexpectedEOF
775
-			}
776
-			if err == io.EOF {
777
-				break
778
-			}
779
-			return err
793
+			return totalSize, err
780 794
 		}
781 795
 		if line[0] != '*' {
782
-			return ErrInvalid
796
+			return totalSize, ErrInvalid
783 797
 		}
798
+		cmdByteSize += int64(len(line))
799
+
784 800
 		// convert the string number to and int
785 801
 		var n int
786 802
 		if len(line) == 4 && line[len(line)-2] == '\r' {
787 803
 			if line[1] < '0' || line[1] > '9' {
788
-				return ErrInvalid
804
+				return totalSize, ErrInvalid
789 805
 			}
790 806
 			n = int(line[1] - '0')
791 807
 		} else {
792 808
 			if len(line) < 5 || line[len(line)-2] != '\r' {
793
-				return ErrInvalid
809
+				return totalSize, ErrInvalid
794 810
 			}
795 811
 			for i := 1; i < len(line)-2; i++ {
796 812
 				if line[i] < '0' || line[i] > '9' {
797
-					return ErrInvalid
813
+					return totalSize, ErrInvalid
798 814
 				}
799 815
 				n = n*10 + int(line[i]-'0')
800 816
 			}
@@ -805,25 +821,26 @@ func (db *DB) readLoad(rd io.Reader, modTime time.Time) error {
805 821
 			// read the number of bytes of the part.
806 822
 			line, err := r.ReadBytes('\n')
807 823
 			if err != nil {
808
-				return err
824
+				return totalSize, err
809 825
 			}
810 826
 			if line[0] != '$' {
811
-				return ErrInvalid
827
+				return totalSize, ErrInvalid
812 828
 			}
829
+			cmdByteSize += int64(len(line))
813 830
 			// convert the string number to and int
814 831
 			var n int
815 832
 			if len(line) == 4 && line[len(line)-2] == '\r' {
816 833
 				if line[1] < '0' || line[1] > '9' {
817
-					return ErrInvalid
834
+					return totalSize, ErrInvalid
818 835
 				}
819 836
 				n = int(line[1] - '0')
820 837
 			} else {
821 838
 				if len(line) < 5 || line[len(line)-2] != '\r' {
822
-					return ErrInvalid
839
+					return totalSize, ErrInvalid
823 840
 				}
824 841
 				for i := 1; i < len(line)-2; i++ {
825 842
 					if line[i] < '0' || line[i] > '9' {
826
-						return ErrInvalid
843
+						return totalSize, ErrInvalid
827 844
 					}
828 845
 					n = n*10 + int(line[i]-'0')
829 846
 				}
@@ -837,13 +854,14 @@ func (db *DB) readLoad(rd io.Reader, modTime time.Time) error {
837 854
 				data = make([]byte, dataln)
838 855
 			}
839 856
 			if _, err = io.ReadFull(r, data[:n+2]); err != nil {
840
-				return err
857
+				return totalSize, err
841 858
 			}
842 859
 			if data[n] != '\r' || data[n+1] != '\n' {
843
-				return ErrInvalid
860
+				return totalSize, ErrInvalid
844 861
 			}
845 862
 			// copy string
846 863
 			parts = append(parts, string(data[:n]))
864
+			cmdByteSize += int64(n + 2)
847 865
 		}
848 866
 		// finished reading the command
849 867
 
@@ -855,15 +873,15 @@ func (db *DB) readLoad(rd io.Reader, modTime time.Time) error {
855 873
 			(parts[0][2] == 't' || parts[0][2] == 'T') {
856 874
 			// SET
857 875
 			if len(parts) < 3 || len(parts) == 4 || len(parts) > 5 {
858
-				return ErrInvalid
876
+				return totalSize, ErrInvalid
859 877
 			}
860 878
 			if len(parts) == 5 {
861 879
 				if strings.ToLower(parts[3]) != "ex" {
862
-					return ErrInvalid
880
+					return totalSize, ErrInvalid
863 881
 				}
864
-				ex, err := strconv.ParseInt(parts[4], 10, 64)
882
+				ex, err := strconv.ParseUint(parts[4], 10, 64)
865 883
 				if err != nil {
866
-					return err
884
+					return totalSize, err
867 885
 				}
868 886
 				now := time.Now()
869 887
 				dur := (time.Duration(ex) * time.Second) - now.Sub(modTime)
@@ -885,7 +903,7 @@ func (db *DB) readLoad(rd io.Reader, modTime time.Time) error {
885 903
 			(parts[0][2] == 'l' || parts[0][2] == 'L') {
886 904
 			// DEL
887 905
 			if len(parts) != 2 {
888
-				return ErrInvalid
906
+				return totalSize, ErrInvalid
889 907
 			}
890 908
 			db.deleteFromDatabase(&dbItem{key: parts[1]})
891 909
 		} else if (parts[0][0] == 'f' || parts[0][0] == 'F') &&
@@ -894,10 +912,10 @@ func (db *DB) readLoad(rd io.Reader, modTime time.Time) error {
894 912
 			db.exps = btree.New(lessCtx(&exctx{db}))
895 913
 			db.idxs = make(map[string]*index)
896 914
 		} else {
897
-			return ErrInvalid
915
+			return totalSize, ErrInvalid
898 916
 		}
917
+		totalSize += cmdByteSize
899 918
 	}
900
-	return nil
901 919
 }
902 920
 
903 921
 // load reads entries from the append only database file and fills the database.
@@ -910,10 +928,20 @@ func (db *DB) load() error {
910 928
 	if err != nil {
911 929
 		return err
912 930
 	}
913
-	if err := db.readLoad(db.file, fi.ModTime()); err != nil {
914
-		return err
931
+	n, err := db.readLoad(db.file, fi.ModTime())
932
+	if err != nil {
933
+		if err == io.ErrUnexpectedEOF {
934
+			// The db file has ended mid-command, which is allowed but the
935
+			// data file should be truncated to the end of the last valid
936
+			// command
937
+			if err := db.file.Truncate(n); err != nil {
938
+				return err
939
+			}
940
+		} else {
941
+			return err
942
+		}
915 943
 	}
916
-	pos, err := db.file.Seek(0, 2)
944
+	pos, err := db.file.Seek(n, 0)
917 945
 	if err != nil {
918 946
 		return err
919 947
 	}
@@ -1148,7 +1176,25 @@ func (tx *Tx) Commit() error {
1148 1176
 		// Flushing the buffer only once per transaction.
1149 1177
 		// If this operation fails then the write did failed and we must
1150 1178
 		// rollback.
1151
-		if _, err = tx.db.file.Write(tx.db.buf); err != nil {
1179
+		var n int
1180
+		n, err = tx.db.file.Write(tx.db.buf)
1181
+		if err != nil {
1182
+			if n > 0 {
1183
+				// There was a partial write to disk.
1184
+				// We are possibly out of disk space.
1185
+				// Delete the partially written bytes from the data file by
1186
+				// seeking to the previously known position and performing
1187
+				// a truncate operation.
1188
+				// At this point a syscall failure is fatal and the process
1189
+				// should be killed to avoid corrupting the file.
1190
+				pos, err := tx.db.file.Seek(-int64(n), 1)
1191
+				if err != nil {
1192
+					panic(err)
1193
+				}
1194
+				if err := tx.db.file.Truncate(pos); err != nil {
1195
+					panic(err)
1196
+				}
1197
+			}
1152 1198
 			tx.rollbackInner()
1153 1199
 		}
1154 1200
 		if tx.db.config.SyncPolicy == Always {
@@ -1216,7 +1262,7 @@ func appendBulkString(buf []byte, s string) []byte {
1216 1262
 // writeSetTo writes an item as a single SET record to the a bufio Writer.
1217 1263
 func (dbi *dbItem) writeSetTo(buf []byte) []byte {
1218 1264
 	if dbi.opts != nil && dbi.opts.ex {
1219
-		ex := dbi.opts.exat.Sub(time.Now()) / time.Second
1265
+		ex := time.Until(dbi.opts.exat) / time.Second
1220 1266
 		buf = appendArray(buf, 5)
1221 1267
 		buf = appendBulkString(buf, "set")
1222 1268
 		buf = appendBulkString(buf, dbi.key)
@@ -1390,7 +1436,9 @@ func (tx *Tx) Set(key, value string, opts *SetOptions) (previousValue string,
1390 1436
 			// create a rollback entry with a nil value. A nil value indicates
1391 1437
 			// that the entry should be deleted on rollback. When the value is
1392 1438
 			// *not* nil, that means the entry should be reverted.
1393
-			tx.wc.rollbackItems[key] = nil
1439
+			if _, ok := tx.wc.rollbackItems[key]; !ok {
1440
+				tx.wc.rollbackItems[key] = nil
1441
+			}
1394 1442
 		} else {
1395 1443
 			// A previous item already exists in the database. Let's create a
1396 1444
 			// rollback entry with the item as the value. We need to check the
@@ -1481,7 +1529,7 @@ func (tx *Tx) TTL(key string) (time.Duration, error) {
1481 1529
 	} else if item.opts == nil || !item.opts.ex {
1482 1530
 		return -1, nil
1483 1531
 	}
1484
-	dur := item.opts.exat.Sub(time.Now())
1532
+	dur := time.Until(item.opts.exat)
1485 1533
 	if dur < 0 {
1486 1534
 		return 0, ErrNotFound
1487 1535
 	}
@@ -1822,7 +1870,7 @@ func (tx *Tx) Nearby(index, bounds string,
1822 1870
 		return nil
1823 1871
 	}
1824 1872
 	// // wrap a rtree specific iterator around the user-defined iterator.
1825
-	iter := func(item rtree.Item, dist float64) bool {
1873
+	iter := func(item rtred.Item, dist float64) bool {
1826 1874
 		dbi := item.(*dbItem)
1827 1875
 		return iterator(dbi.key, dbi.val, dist)
1828 1876
 	}
@@ -1860,7 +1908,7 @@ func (tx *Tx) Intersects(index, bounds string,
1860 1908
 		return nil
1861 1909
 	}
1862 1910
 	// wrap a rtree specific iterator around the user-defined iterator.
1863
-	iter := func(item rtree.Item) bool {
1911
+	iter := func(item rtred.Item) bool {
1864 1912
 		dbi := item.(*dbItem)
1865 1913
 		return iterator(dbi.key, dbi.val)
1866 1914
 	}

+ 7
- 7
vendor/github.com/tidwall/buntdb/go.mod View File

@@ -1,12 +1,12 @@
1 1
 module github.com/tidwall/buntdb
2 2
 
3
-go 1.15
3
+go 1.16
4 4
 
5 5
 require (
6
-	github.com/tidwall/btree v0.2.2
7
-	github.com/tidwall/gjson v1.6.1
8
-	github.com/tidwall/grect v0.0.0-20161006141115-ba9a043346eb
9
-	github.com/tidwall/match v1.0.1
10
-	github.com/tidwall/rtree v0.0.0-20201027154624-32188eeb08a8
11
-	github.com/tidwall/tinyqueue v0.0.0-20180302190814-1e39f5511563 // indirect
6
+	github.com/tidwall/btree v0.4.2
7
+	github.com/tidwall/gjson v1.7.4
8
+	github.com/tidwall/grect v0.1.1
9
+	github.com/tidwall/lotsa v1.0.2
10
+	github.com/tidwall/match v1.0.3
11
+	github.com/tidwall/rtred v0.1.2
12 12
 )

+ 16
- 14
vendor/github.com/tidwall/buntdb/go.sum View File

@@ -1,14 +1,16 @@
1
-github.com/tidwall/btree v0.2.2 h1:VVo0JW/tdidNdQzNsDR4wMbL3heaxA1DGleyzQ3/niY=
2
-github.com/tidwall/btree v0.2.2/go.mod h1:huei1BkDWJ3/sLXmO+bsCNELL+Bp2Kks9OLyQFkzvA8=
3
-github.com/tidwall/gjson v1.6.1 h1:LRbvNuNuvAiISWg6gxLEFuCe72UKy5hDqhxW/8183ws=
4
-github.com/tidwall/gjson v1.6.1/go.mod h1:BaHyNc5bjzYkPqgLq7mdVzeiRtULKULXLgZFKsxEHI0=
5
-github.com/tidwall/grect v0.0.0-20161006141115-ba9a043346eb h1:5NSYaAdrnblKByzd7XByQEJVT8+9v0W/tIY0Oo4OwrE=
6
-github.com/tidwall/grect v0.0.0-20161006141115-ba9a043346eb/go.mod h1:lKYYLFIr9OIgdgrtgkZ9zgRxRdvPYsExnYBsEAd8W5M=
7
-github.com/tidwall/match v1.0.1 h1:PnKP62LPNxHKTwvHHZZzdOAOCtsJTjo6dZLCwpKm5xc=
8
-github.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E=
9
-github.com/tidwall/pretty v1.0.2 h1:Z7S3cePv9Jwm1KwS0513MRaoUe3S01WPbLNV40pwWZU=
10
-github.com/tidwall/pretty v1.0.2/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
11
-github.com/tidwall/rtree v0.0.0-20201027154624-32188eeb08a8 h1:BsKSRhu0TDB6Snq8SutN9KQHc6vqHEXJTcAFwyGNius=
12
-github.com/tidwall/rtree v0.0.0-20201027154624-32188eeb08a8/go.mod h1:/h+UnNGt0IhNNJLkGikcdcJqm66zGD/uJGMRxK/9+Ao=
13
-github.com/tidwall/tinyqueue v0.0.0-20180302190814-1e39f5511563 h1:Otn9S136ELckZ3KKDyCkxapfufrqDqwmGjcHfAyXRrE=
14
-github.com/tidwall/tinyqueue v0.0.0-20180302190814-1e39f5511563/go.mod h1:mLqSmt7Dv/CNneF2wfcChfN1rvapyQr01LGKnKex0DQ=
1
+github.com/tidwall/btree v0.4.2 h1:aLwwJlG+InuFzdAPuBf9YCAR1LvSQ9zhC5aorFPlIPs=
2
+github.com/tidwall/btree v0.4.2/go.mod h1:huei1BkDWJ3/sLXmO+bsCNELL+Bp2Kks9OLyQFkzvA8=
3
+github.com/tidwall/gjson v1.7.4 h1:19cchw8FOxkG5mdLRkGf9jqIqEyqdZhPqW60XfyFxk8=
4
+github.com/tidwall/gjson v1.7.4/go.mod h1:5/xDoumyyDNerp2U36lyolv46b3uF/9Bu6OfyQ9GImk=
5
+github.com/tidwall/grect v0.1.1 h1:+kMEkxhoqB7rniVXzMEIA66XwU07STgINqxh+qVIndY=
6
+github.com/tidwall/grect v0.1.1/go.mod h1:CzvbGiFbWUwiJ1JohXLb28McpyBsI00TK9Y6pDWLGRQ=
7
+github.com/tidwall/lotsa v1.0.2 h1:dNVBH5MErdaQ/xd9s769R31/n2dXavsQ0Yf4TMEHHw8=
8
+github.com/tidwall/lotsa v1.0.2/go.mod h1:X6NiU+4yHA3fE3Puvpnn1XMDrFZrE9JO2/w+UMuqgR8=
9
+github.com/tidwall/match v1.0.3 h1:FQUVvBImDutD8wJLN6c5eMzWtjgONK9MwIBCOrUJKeE=
10
+github.com/tidwall/match v1.0.3/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
11
+github.com/tidwall/pretty v1.1.0 h1:K3hMW5epkdAVwibsQEfR/7Zj0Qgt4DxtNumTq/VloO8=
12
+github.com/tidwall/pretty v1.1.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
13
+github.com/tidwall/rtred v0.1.2 h1:exmoQtOLvDoO8ud++6LwVsAMTu0KPzLTUrMln8u1yu8=
14
+github.com/tidwall/rtred v0.1.2/go.mod h1:hd69WNXQ5RP9vHd7dqekAz+RIdtfBogmglkZSRxCHFQ=
15
+github.com/tidwall/tinyqueue v0.1.1 h1:SpNEvEggbpyN5DIReaJ2/1ndroY8iyEGxPYxoSaymYE=
16
+github.com/tidwall/tinyqueue v0.1.1/go.mod h1:O/QNHwrnjqr6IHItYrzoHAKYhBkLI67Q096fQP5zMYw=

+ 0
- 1
vendor/github.com/tidwall/gjson/.travis.yml View File

@@ -1 +0,0 @@
1
-language: go

+ 4
- 13
vendor/github.com/tidwall/gjson/README.md View File

@@ -3,13 +3,10 @@
3 3
     src="logo.png" 
4 4
     width="240" height="78" border="0" alt="GJSON">
5 5
 <br>
6
-<a href="https://travis-ci.org/tidwall/gjson"><img src="https://img.shields.io/travis/tidwall/gjson.svg?style=flat-square" alt="Build Status"></a>
7 6
 <a href="https://godoc.org/github.com/tidwall/gjson"><img src="https://img.shields.io/badge/api-reference-blue.svg?style=flat-square" alt="GoDoc"></a>
8 7
 <a href="http://tidwall.com/gjson-play"><img src="https://img.shields.io/badge/%F0%9F%8F%90-playground-9900cc.svg?style=flat-square" alt="GJSON Playground"></a>
9 8
 </p>
10 9
 
11
-
12
-
13 10
 <p align="center">get json values quickly</a></p>
14 11
 
15 12
 GJSON is a Go package that provides a [fast](#performance) and [simple](#get-a-value) way to get values from a json document.
@@ -17,6 +14,8 @@ It has features such as [one line retrieval](#get-a-value), [dot notation paths]
17 14
 
18 15
 Also check out [SJSON](https://github.com/tidwall/sjson) for modifying json, and the [JJ](https://github.com/tidwall/jj) command line tool.
19 16
 
17
+For the Rust version go to [gjson.rs](https://github.com/tidwall/gjson.rs).
18
+
20 19
 Getting Started
21 20
 ===============
22 21
 
@@ -476,7 +475,7 @@ JSON document used:
476 475
 }    
477 476
 ```
478 477
 
479
-Each operation was rotated though one of the following search paths:
478
+Each operation was rotated through one of the following search paths:
480 479
 
481 480
 ```
482 481
 widget.window.name
@@ -484,12 +483,4 @@ widget.image.hOffset
484 483
 widget.text.onMouseUp
485 484
 ```
486 485
 
487
-*These benchmarks were run on a MacBook Pro 15" 2.8 GHz Intel Core i7 using Go 1.8 and can be be found [here](https://github.com/tidwall/gjson-benchmarks).*
488
-
489
-
490
-## Contact
491
-Josh Baker [@tidwall](http://twitter.com/tidwall)
492
-
493
-## License
494
-
495
-GJSON source code is available under the MIT [License](/LICENSE).
486
+*These benchmarks were run on a MacBook Pro 15" 2.8 GHz Intel Core i7 using Go 1.8 and can be found [here](https://github.com/tidwall/gjson-benchmarks).*

+ 12
- 3
vendor/github.com/tidwall/gjson/SYNTAX.md View File

@@ -77,14 +77,21 @@ Special purpose characters, such as `.`, `*`, and `?` can be escaped with `\`.
77 77
 fav\.movie             "Deer Hunter"
78 78
 ```
79 79
 
80
-You'll also need to make sure that the `\` character is correctly escaped when hardcoding a path in source code.
80
+You'll also need to make sure that the `\` character is correctly escaped when hardcoding a path in you source code.
81 81
 
82 82
 ```go
83
-res := gjson.Get(json, "fav\\.movie")  // must escape the slash
84
-res := gjson.Get(json, `fav\.movie`)   // no need to escape the slash 
83
+// Go
84
+val := gjson.Get(json, "fav\\.movie")  // must escape the slash
85
+val := gjson.Get(json, `fav\.movie`)   // no need to escape the slash 
86
+```
85 87
 
88
+```rust
89
+// Rust
90
+let val = gjson::get(json, "fav\\.movie")     // must escape the slash
91
+let val = gjson::get(json, r#"fav\.movie"#)   // no need to escape the slash 
86 92
 ```
87 93
 
94
+
88 95
 ### Arrays
89 96
 
90 97
 The `#` character allows for digging into JSON Arrays.
@@ -248,6 +255,8 @@ gjson.AddModifier("case", func(json, arg string) string {
248 255
 "children.@case:lower.@reverse"    ["jack","alex","sara"]
249 256
 ```
250 257
 
258
+*Note: Custom modifiers are not yet available in the Rust version*
259
+
251 260
 ### Multipaths
252 261
 
253 262
 Starting with v1.3.0, GJSON added the ability to join multiple paths together

+ 131
- 89
vendor/github.com/tidwall/gjson/gjson.go View File

@@ -3,7 +3,6 @@ package gjson
3 3
 
4 4
 import (
5 5
 	"encoding/json"
6
-	"reflect"
7 6
 	"strconv"
8 7
 	"strings"
9 8
 	"time"
@@ -106,7 +105,8 @@ func (t Result) Bool() bool {
106 105
 	case True:
107 106
 		return true
108 107
 	case String:
109
-		return t.Str != "" && t.Str != "0" && t.Str != "false"
108
+		b, _ := strconv.ParseBool(strings.ToLower(t.Str))
109
+		return b
110 110
 	case Number:
111 111
 		return t.Num != 0
112 112
 	}
@@ -124,16 +124,17 @@ func (t Result) Int() int64 {
124 124
 		return n
125 125
 	case Number:
126 126
 		// try to directly convert the float64 to int64
127
-		n, ok := floatToInt(t.Num)
128
-		if !ok {
129
-			// now try to parse the raw string
130
-			n, ok = parseInt(t.Raw)
131
-			if !ok {
132
-				// fallback to a standard conversion
133
-				return int64(t.Num)
134
-			}
127
+		i, ok := safeInt(t.Num)
128
+		if ok {
129
+			return i
135 130
 		}
136
-		return n
131
+		// now try to parse the raw string
132
+		i, ok = parseInt(t.Raw)
133
+		if ok {
134
+			return i
135
+		}
136
+		// fallback to a standard conversion
137
+		return int64(t.Num)
137 138
 	}
138 139
 }
139 140
 
@@ -149,16 +150,17 @@ func (t Result) Uint() uint64 {
149 150
 		return n
150 151
 	case Number:
151 152
 		// try to directly convert the float64 to uint64
152
-		n, ok := floatToUint(t.Num)
153
-		if !ok {
154
-			// now try to parse the raw string
155
-			n, ok = parseUint(t.Raw)
156
-			if !ok {
157
-				// fallback to a standard conversion
158
-				return uint64(t.Num)
159
-			}
153
+		i, ok := safeInt(t.Num)
154
+		if ok && i >= 0 {
155
+			return uint64(i)
160 156
 		}
161
-		return n
157
+		// now try to parse the raw string
158
+		u, ok := parseUint(t.Raw)
159
+		if ok {
160
+			return u
161
+		}
162
+		// fallback to a standard conversion
163
+		return uint64(t.Num)
162 164
 	}
163 165
 }
164 166
 
@@ -495,6 +497,9 @@ func squash(json string) string {
495 497
 					}
496 498
 				}
497 499
 				if depth == 0 {
500
+					if i >= len(json) {
501
+						return json
502
+					}
498 503
 					return json[:i+1]
499 504
 				}
500 505
 			case '{', '[', '(':
@@ -726,8 +731,13 @@ func parseArrayPath(path string) (r arrayPathResult) {
726 731
 		}
727 732
 		if path[i] == '.' {
728 733
 			r.part = path[:i]
729
-			r.path = path[i+1:]
730
-			r.more = true
734
+			if !r.arrch && i < len(path)-1 && isDotPiperChar(path[i+1]) {
735
+				r.pipe = path[i+1:]
736
+				r.piped = true
737
+			} else {
738
+				r.path = path[i+1:]
739
+				r.more = true
740
+			}
731 741
 			return
732 742
 		}
733 743
 		if path[i] == '#' {
@@ -973,6 +983,11 @@ right:
973 983
 	return s
974 984
 }
975 985
 
986
+// peek at the next byte and see if it's a '@', '[', or '{'.
987
+func isDotPiperChar(c byte) bool {
988
+	return !DisableModifiers && (c == '@' || c == '[' || c == '{')
989
+}
990
+
976 991
 type objectPathResult struct {
977 992
 	part  string
978 993
 	path  string
@@ -991,12 +1006,8 @@ func parseObjectPath(path string) (r objectPathResult) {
991 1006
 			return
992 1007
 		}
993 1008
 		if path[i] == '.' {
994
-			// peek at the next byte and see if it's a '@', '[', or '{'.
995 1009
 			r.part = path[:i]
996
-			if !DisableModifiers &&
997
-				i < len(path)-1 &&
998
-				(path[i+1] == '@' ||
999
-					path[i+1] == '[' || path[i+1] == '{') {
1010
+			if i < len(path)-1 && isDotPiperChar(path[i+1]) {
1000 1011
 				r.pipe = path[i+1:]
1001 1012
 				r.piped = true
1002 1013
 			} else {
@@ -1026,14 +1037,11 @@ func parseObjectPath(path string) (r objectPathResult) {
1026 1037
 						continue
1027 1038
 					} else if path[i] == '.' {
1028 1039
 						r.part = string(epart)
1029
-						// peek at the next byte and see if it's a '@' modifier
1030
-						if !DisableModifiers &&
1031
-							i < len(path)-1 && path[i+1] == '@' {
1040
+						if i < len(path)-1 && isDotPiperChar(path[i+1]) {
1032 1041
 							r.pipe = path[i+1:]
1033 1042
 							r.piped = true
1034 1043
 						} else {
1035 1044
 							r.path = path[i+1:]
1036
-							r.more = true
1037 1045
 						}
1038 1046
 						r.more = true
1039 1047
 						return
@@ -1398,7 +1406,6 @@ func parseArray(c *parseContext, i int, path string) (int, bool) {
1398 1406
 		}
1399 1407
 		return false
1400 1408
 	}
1401
-
1402 1409
 	for i < len(c.json)+1 {
1403 1410
 		if !rp.arrch {
1404 1411
 			pmatch = partidx == h
@@ -1600,10 +1607,17 @@ func parseArray(c *parseContext, i int, path string) (int, bool) {
1600 1607
 					c.calcd = true
1601 1608
 					return i + 1, true
1602 1609
 				}
1603
-				if len(multires) > 0 && !c.value.Exists() {
1604
-					c.value = Result{
1605
-						Raw:  string(append(multires, ']')),
1606
-						Type: JSON,
1610
+				if !c.value.Exists() {
1611
+					if len(multires) > 0 {
1612
+						c.value = Result{
1613
+							Raw:  string(append(multires, ']')),
1614
+							Type: JSON,
1615
+						}
1616
+					} else if rp.query.all {
1617
+						c.value = Result{
1618
+							Raw:  "[]",
1619
+							Type: JSON,
1620
+						}
1607 1621
 					}
1608 1622
 				}
1609 1623
 				return i + 1, false
@@ -1835,7 +1849,7 @@ type parseContext struct {
1835 1849
 // A path is in dot syntax, such as "name.last" or "age".
1836 1850
 // When the value is found it's returned immediately.
1837 1851
 //
1838
-// A path is a series of keys searated by a dot.
1852
+// A path is a series of keys separated by a dot.
1839 1853
 // A key may contain special wildcard characters '*' and '?'.
1840 1854
 // To access an array value use the index as the key.
1841 1855
 // To get the number of elements in an array or to access a child path, use
@@ -1944,7 +1958,6 @@ func Get(json, path string) Result {
1944 1958
 			}
1945 1959
 		}
1946 1960
 	}
1947
-
1948 1961
 	var i int
1949 1962
 	var c = &parseContext{json: json}
1950 1963
 	if len(path) >= 2 && path[0] == '.' && path[1] == '.' {
@@ -2169,11 +2182,6 @@ func parseAny(json string, i int, hit bool) (int, Result, bool) {
2169 2182
 	return i, res, false
2170 2183
 }
2171 2184
 
2172
-var ( // used for testing
2173
-	testWatchForFallback bool
2174
-	testLastWasFallback  bool
2175
-)
2176
-
2177 2185
 // GetMany searches json for the multiple paths.
2178 2186
 // The return value is a Result array where the number of items
2179 2187
 // will be equal to the number of input paths.
@@ -2374,6 +2382,12 @@ func validnumber(data []byte, i int) (outi int, ok bool) {
2374 2382
 	// sign
2375 2383
 	if data[i] == '-' {
2376 2384
 		i++
2385
+		if i == len(data) {
2386
+			return i, false
2387
+		}
2388
+		if data[i] < '0' || data[i] > '9' {
2389
+			return i, false
2390
+		}
2377 2391
 	}
2378 2392
 	// int
2379 2393
 	if i == len(data) {
@@ -2524,25 +2538,14 @@ func parseInt(s string) (n int64, ok bool) {
2524 2538
 	return n, true
2525 2539
 }
2526 2540
 
2527
-const minUint53 = 0
2528
-const maxUint53 = 4503599627370495
2529
-const minInt53 = -2251799813685248
2530
-const maxInt53 = 2251799813685247
2531
-
2532
-func floatToUint(f float64) (n uint64, ok bool) {
2533
-	n = uint64(f)
2534
-	if float64(n) == f && n >= minUint53 && n <= maxUint53 {
2535
-		return n, true
2536
-	}
2537
-	return 0, false
2538
-}
2539
-
2540
-func floatToInt(f float64) (n int64, ok bool) {
2541
-	n = int64(f)
2542
-	if float64(n) == f && n >= minInt53 && n <= maxInt53 {
2543
-		return n, true
2541
+// safeInt validates a given JSON number
2542
+// ensures it lies within the minimum and maximum representable JSON numbers
2543
+func safeInt(f float64) (n int64, ok bool) {
2544
+	//  https://tc39.es/ecma262/#sec-number.min_safe_integer || https://tc39.es/ecma262/#sec-number.max_safe_integer
2545
+	if f < -9007199254740991 || f > 9007199254740991 {
2546
+		return 0, false
2544 2547
 	}
2545
-	return 0, false
2548
+	return int64(f), true
2546 2549
 }
2547 2550
 
2548 2551
 // execModifier parses the path to find a matching modifier function.
@@ -2600,7 +2603,7 @@ func execModifier(json, path string) (pathOut, res string, ok bool) {
2600 2603
 // unwrap removes the '[]' or '{}' characters around json
2601 2604
 func unwrap(json string) string {
2602 2605
 	json = trim(json)
2603
-	if len(json) >= 2 && json[0] == '[' || json[0] == '{' {
2606
+	if len(json) >= 2 && (json[0] == '[' || json[0] == '{') {
2604 2607
 		json = json[1 : len(json)-1]
2605 2608
 	}
2606 2609
 	return json
@@ -2632,6 +2635,26 @@ func ModifierExists(name string, fn func(json, arg string) string) bool {
2632 2635
 	return ok
2633 2636
 }
2634 2637
 
2638
+// cleanWS remove any non-whitespace from string
2639
+func cleanWS(s string) string {
2640
+	for i := 0; i < len(s); i++ {
2641
+		switch s[i] {
2642
+		case ' ', '\t', '\n', '\r':
2643
+			continue
2644
+		default:
2645
+			var s2 []byte
2646
+			for i := 0; i < len(s); i++ {
2647
+				switch s[i] {
2648
+				case ' ', '\t', '\n', '\r':
2649
+					s2 = append(s2, s[i])
2650
+				}
2651
+			}
2652
+			return string(s2)
2653
+		}
2654
+	}
2655
+	return s
2656
+}
2657
+
2635 2658
 // @pretty modifier makes the json look nice.
2636 2659
 func modPretty(json, arg string) string {
2637 2660
 	if len(arg) > 0 {
@@ -2641,9 +2664,9 @@ func modPretty(json, arg string) string {
2641 2664
 			case "sortKeys":
2642 2665
 				opts.SortKeys = value.Bool()
2643 2666
 			case "indent":
2644
-				opts.Indent = value.String()
2667
+				opts.Indent = cleanWS(value.String())
2645 2668
 			case "prefix":
2646
-				opts.Prefix = value.String()
2669
+				opts.Prefix = cleanWS(value.String())
2647 2670
 			case "width":
2648 2671
 				opts.Width = int(value.Int())
2649 2672
 			}
@@ -2729,19 +2752,24 @@ func modFlatten(json, arg string) string {
2729 2752
 	out = append(out, '[')
2730 2753
 	var idx int
2731 2754
 	res.ForEach(func(_, value Result) bool {
2732
-		if idx > 0 {
2733
-			out = append(out, ',')
2734
-		}
2755
+		var raw string
2735 2756
 		if value.IsArray() {
2736 2757
 			if deep {
2737
-				out = append(out, unwrap(modFlatten(value.Raw, arg))...)
2758
+				raw = unwrap(modFlatten(value.Raw, arg))
2738 2759
 			} else {
2739
-				out = append(out, unwrap(value.Raw)...)
2760
+				raw = unwrap(value.Raw)
2740 2761
 			}
2741 2762
 		} else {
2742
-			out = append(out, value.Raw...)
2763
+			raw = value.Raw
2764
+		}
2765
+		raw = strings.TrimSpace(raw)
2766
+		if len(raw) > 0 {
2767
+			if idx > 0 {
2768
+				out = append(out, ',')
2769
+			}
2770
+			out = append(out, raw...)
2771
+			idx++
2743 2772
 		}
2744
-		idx++
2745 2773
 		return true
2746 2774
 	})
2747 2775
 	out = append(out, ']')
@@ -2825,6 +2853,19 @@ func modValid(json, arg string) string {
2825 2853
 	return json
2826 2854
 }
2827 2855
 
2856
+// stringHeader instead of reflect.StringHeader
2857
+type stringHeader struct {
2858
+	data unsafe.Pointer
2859
+	len  int
2860
+}
2861
+
2862
+// sliceHeader instead of reflect.SliceHeader
2863
+type sliceHeader struct {
2864
+	data unsafe.Pointer
2865
+	len  int
2866
+	cap  int
2867
+}
2868
+
2828 2869
 // getBytes casts the input json bytes to a string and safely returns the
2829 2870
 // results as uniquely allocated data. This operation is intended to minimize
2830 2871
 // copies and allocations for the large json string->[]byte.
@@ -2834,14 +2875,14 @@ func getBytes(json []byte, path string) Result {
2834 2875
 		// unsafe cast to string
2835 2876
 		result = Get(*(*string)(unsafe.Pointer(&json)), path)
2836 2877
 		// safely get the string headers
2837
-		rawhi := *(*reflect.StringHeader)(unsafe.Pointer(&result.Raw))
2838
-		strhi := *(*reflect.StringHeader)(unsafe.Pointer(&result.Str))
2878
+		rawhi := *(*stringHeader)(unsafe.Pointer(&result.Raw))
2879
+		strhi := *(*stringHeader)(unsafe.Pointer(&result.Str))
2839 2880
 		// create byte slice headers
2840
-		rawh := reflect.SliceHeader{Data: rawhi.Data, Len: rawhi.Len}
2841
-		strh := reflect.SliceHeader{Data: strhi.Data, Len: strhi.Len}
2842
-		if strh.Data == 0 {
2881
+		rawh := sliceHeader{data: rawhi.data, len: rawhi.len, cap: rawhi.len}
2882
+		strh := sliceHeader{data: strhi.data, len: strhi.len, cap: rawhi.len}
2883
+		if strh.data == nil {
2843 2884
 			// str is nil
2844
-			if rawh.Data == 0 {
2885
+			if rawh.data == nil {
2845 2886
 				// raw is nil
2846 2887
 				result.Raw = ""
2847 2888
 			} else {
@@ -2849,19 +2890,20 @@ func getBytes(json []byte, path string) Result {
2849 2890
 				result.Raw = string(*(*[]byte)(unsafe.Pointer(&rawh)))
2850 2891
 			}
2851 2892
 			result.Str = ""
2852
-		} else if rawh.Data == 0 {
2893
+		} else if rawh.data == nil {
2853 2894
 			// raw is nil
2854 2895
 			result.Raw = ""
2855 2896
 			// str has data, safely copy the slice header to a string
2856 2897
 			result.Str = string(*(*[]byte)(unsafe.Pointer(&strh)))
2857
-		} else if strh.Data >= rawh.Data &&
2858
-			int(strh.Data)+strh.Len <= int(rawh.Data)+rawh.Len {
2898
+		} else if uintptr(strh.data) >= uintptr(rawh.data) &&
2899
+			uintptr(strh.data)+uintptr(strh.len) <=
2900
+				uintptr(rawh.data)+uintptr(rawh.len) {
2859 2901
 			// Str is a substring of Raw.
2860
-			start := int(strh.Data - rawh.Data)
2902
+			start := uintptr(strh.data) - uintptr(rawh.data)
2861 2903
 			// safely copy the raw slice header
2862 2904
 			result.Raw = string(*(*[]byte)(unsafe.Pointer(&rawh)))
2863 2905
 			// substring the raw
2864
-			result.Str = result.Raw[start : start+strh.Len]
2906
+			result.Str = result.Raw[start : start+uintptr(strh.len)]
2865 2907
 		} else {
2866 2908
 			// safely copy both the raw and str slice headers to strings
2867 2909
 			result.Raw = string(*(*[]byte)(unsafe.Pointer(&rawh)))
@@ -2876,9 +2918,9 @@ func getBytes(json []byte, path string) Result {
2876 2918
 // used instead.
2877 2919
 func fillIndex(json string, c *parseContext) {
2878 2920
 	if len(c.value.Raw) > 0 && !c.calcd {
2879
-		jhdr := *(*reflect.StringHeader)(unsafe.Pointer(&json))
2880
-		rhdr := *(*reflect.StringHeader)(unsafe.Pointer(&(c.value.Raw)))
2881
-		c.value.Index = int(rhdr.Data - jhdr.Data)
2921
+		jhdr := *(*stringHeader)(unsafe.Pointer(&json))
2922
+		rhdr := *(*stringHeader)(unsafe.Pointer(&(c.value.Raw)))
2923
+		c.value.Index = int(uintptr(rhdr.data) - uintptr(jhdr.data))
2882 2924
 		if c.value.Index < 0 || c.value.Index >= len(json) {
2883 2925
 			c.value.Index = 0
2884 2926
 		}
@@ -2886,10 +2928,10 @@ func fillIndex(json string, c *parseContext) {
2886 2928
 }
2887 2929
 
2888 2930
 func stringBytes(s string) []byte {
2889
-	return *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{
2890
-		Data: (*reflect.StringHeader)(unsafe.Pointer(&s)).Data,
2891
-		Len:  len(s),
2892
-		Cap:  len(s),
2931
+	return *(*[]byte)(unsafe.Pointer(&sliceHeader{
2932
+		data: (*stringHeader)(unsafe.Pointer(&s)).data,
2933
+		len:  len(s),
2934
+		cap:  len(s),
2893 2935
 	}))
2894 2936
 }
2895 2937
 

+ 2
- 2
vendor/github.com/tidwall/gjson/go.mod View File

@@ -3,6 +3,6 @@ module github.com/tidwall/gjson
3 3
 go 1.12
4 4
 
5 5
 require (
6
-	github.com/tidwall/match v1.0.1
7
-	github.com/tidwall/pretty v1.0.2
6
+	github.com/tidwall/match v1.0.3
7
+	github.com/tidwall/pretty v1.1.0
8 8
 )

+ 4
- 4
vendor/github.com/tidwall/gjson/go.sum View File

@@ -1,4 +1,4 @@
1
-github.com/tidwall/match v1.0.1 h1:PnKP62LPNxHKTwvHHZZzdOAOCtsJTjo6dZLCwpKm5xc=
2
-github.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E=
3
-github.com/tidwall/pretty v1.0.2 h1:Z7S3cePv9Jwm1KwS0513MRaoUe3S01WPbLNV40pwWZU=
4
-github.com/tidwall/pretty v1.0.2/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
1
+github.com/tidwall/match v1.0.3 h1:FQUVvBImDutD8wJLN6c5eMzWtjgONK9MwIBCOrUJKeE=
2
+github.com/tidwall/match v1.0.3/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
3
+github.com/tidwall/pretty v1.1.0 h1:K3hMW5epkdAVwibsQEfR/7Zj0Qgt4DxtNumTq/VloO8=
4
+github.com/tidwall/pretty v1.1.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=

+ 5
- 0
vendor/github.com/tidwall/grect/go.mod View File

@@ -0,0 +1,5 @@
1
+module github.com/tidwall/grect
2
+
3
+go 1.15
4
+
5
+require github.com/tidwall/gjson v1.7.4

+ 6
- 0
vendor/github.com/tidwall/grect/go.sum View File

@@ -0,0 +1,6 @@
1
+github.com/tidwall/gjson v1.7.4 h1:19cchw8FOxkG5mdLRkGf9jqIqEyqdZhPqW60XfyFxk8=
2
+github.com/tidwall/gjson v1.7.4/go.mod h1:5/xDoumyyDNerp2U36lyolv46b3uF/9Bu6OfyQ9GImk=
3
+github.com/tidwall/match v1.0.3 h1:FQUVvBImDutD8wJLN6c5eMzWtjgONK9MwIBCOrUJKeE=
4
+github.com/tidwall/match v1.0.3/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
5
+github.com/tidwall/pretty v1.1.0 h1:K3hMW5epkdAVwibsQEfR/7Zj0Qgt4DxtNumTq/VloO8=
6
+github.com/tidwall/pretty v1.1.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=

+ 0
- 1
vendor/github.com/tidwall/match/.travis.yml View File

@@ -1 +0,0 @@
1
-language: go

+ 9
- 12
vendor/github.com/tidwall/match/README.md View File

@@ -1,20 +1,17 @@
1
-Match
2
-=====
3
-<a href="https://travis-ci.org/tidwall/match"><img src="https://img.shields.io/travis/tidwall/match.svg?style=flat-square" alt="Build Status"></a>
4
-<a href="https://godoc.org/github.com/tidwall/match"><img src="https://img.shields.io/badge/api-reference-blue.svg?style=flat-square" alt="GoDoc"></a>
1
+# Match
2
+
3
+[![GoDoc](https://godoc.org/github.com/tidwall/match?status.svg)](https://godoc.org/github.com/tidwall/match)
5 4
 
6 5
 Match is a very simple pattern matcher where '*' matches on any 
7 6
 number characters and '?' matches on any one character.
8 7
 
9
-Installing
10
-----------
8
+## Installing
11 9
 
12 10
 ```
13 11
 go get -u github.com/tidwall/match
14 12
 ```
15 13
 
16
-Example
17
--------
14
+## Example
18 15
 
19 16
 ```go
20 17
 match.Match("hello", "*llo") 
@@ -23,10 +20,10 @@ match.Match("hello", "h*o")
23 20
 ```
24 21
 
25 22
 
26
-Contact
27
--------
23
+## Contact
24
+
28 25
 Josh Baker [@tidwall](http://twitter.com/tidwall)
29 26
 
30
-License
31
--------
27
+## License
28
+
32 29
 Redcon source code is available under the MIT [License](/LICENSE).

+ 3
- 0
vendor/github.com/tidwall/match/go.mod View File

@@ -0,0 +1,3 @@
1
+module github.com/tidwall/match
2
+
3
+go 1.15

+ 16
- 5
vendor/github.com/tidwall/match/match.go View File

@@ -1,4 +1,4 @@
1
-// Match provides a simple pattern matcher with unicode support.
1
+// Package match provides a simple pattern matcher with unicode support.
2 2
 package match
3 3
 
4 4
 import "unicode/utf8"
@@ -6,7 +6,7 @@ import "unicode/utf8"
6 6
 // Match returns true if str matches pattern. This is a very
7 7
 // simple wildcard match where '*' matches on any number characters
8 8
 // and '?' matches on any one character.
9
-
9
+//
10 10
 // pattern:
11 11
 // 	{ term }
12 12
 // term:
@@ -16,12 +16,16 @@ import "unicode/utf8"
16 16
 // 	'\\' c      matches character c
17 17
 //
18 18
 func Match(str, pattern string) bool {
19
-	if pattern == "*" {
20
-		return true
21
-	}
22 19
 	return deepMatch(str, pattern)
23 20
 }
21
+
24 22
 func deepMatch(str, pattern string) bool {
23
+	if pattern == "*" {
24
+		return true
25
+	}
26
+	for len(pattern) > 1 && pattern[0] == '*' && pattern[1] == '*' {
27
+		pattern = pattern[1:]
28
+	}
25 29
 	for len(pattern) > 0 {
26 30
 		if pattern[0] > 0x7f {
27 31
 			return deepMatchRune(str, pattern)
@@ -52,6 +56,13 @@ func deepMatch(str, pattern string) bool {
52 56
 }
53 57
 
54 58
 func deepMatchRune(str, pattern string) bool {
59
+	if pattern == "*" {
60
+		return true
61
+	}
62
+	for len(pattern) > 1 && pattern[0] == '*' && pattern[1] == '*' {
63
+		pattern = pattern[1:]
64
+	}
65
+
55 66
 	var sr, pr rune
56 67
 	var srsz, prsz int
57 68
 

+ 0
- 1
vendor/github.com/tidwall/pretty/.travis.yml View File

@@ -1 +0,0 @@
1
-language: go

+ 40
- 3
vendor/github.com/tidwall/pretty/README.md View File

@@ -1,8 +1,6 @@
1 1
 # Pretty
2
-[![Build Status](https://img.shields.io/travis/tidwall/pretty.svg?style=flat-square)](https://travis-ci.org/tidwall/prettty)
3
-[![Coverage Status](https://img.shields.io/badge/coverage-100%25-brightgreen.svg?style=flat-square)](http://gocover.io/github.com/tidwall/pretty)
4
-[![GoDoc](https://img.shields.io/badge/api-reference-blue.svg?style=flat-square)](https://pkg.go.dev/github.com/tidwall/pretty) 
5 2
 
3
+[![GoDoc](https://img.shields.io/badge/api-reference-blue.svg?style=flat-square)](https://pkg.go.dev/github.com/tidwall/pretty) 
6 4
 
7 5
 Pretty is a Go package that provides [fast](#performance) methods for formatting JSON for human readability, or to compact JSON for smaller payloads.
8 6
 
@@ -81,6 +79,45 @@ Will format the json to:
81 79
 {"name":{"first":"Tom","last":"Anderson"},"age":37,"children":["Sara","Alex","Jack"],"fav.movie":"Deer Hunter","friends":[{"first":"Janet","last":"Murphy","age":44}]}```
82 80
 ```
83 81
 
82
+## Spec
83
+
84
+Spec cleans comments and trailing commas from input JSON, converting it to
85
+valid JSON per the official spec: https://tools.ietf.org/html/rfc8259
86
+
87
+The resulting JSON will always be the same length as the input and it will
88
+include all of the same line breaks at matching offsets. This is to ensure
89
+the result can be later processed by a external parser and that that
90
+parser will report messages or errors with the correct offsets.
91
+
92
+The following example uses a JSON document that has comments and trailing
93
+commas and converts it prior to unmarshalling to using the standard Go
94
+JSON library.
95
+
96
+```go
97
+
98
+data := `
99
+{
100
+  /* Dev Machine */
101
+  "dbInfo": {
102
+    "host": "localhost",
103
+    "port": 5432,          // use full email address
104
+    "username": "josh",
105
+    "password": "pass123", // use a hashed password
106
+  }
107
+  /* Only SMTP Allowed */
108
+  "emailInfo": {
109
+    "email": "josh@example.com",
110
+    "password": "pass123",
111
+    "smtp": "smpt.example.com",
112
+  }
113
+}
114
+`
115
+
116
+err := json.Unmarshal(pretty.Spec(data), &config)
117
+
118
+```
119
+
120
+
84 121
 
85 122
 ## Customized output
86 123
 

+ 147
- 11
vendor/github.com/tidwall/pretty/pretty.go View File

@@ -118,21 +118,27 @@ type pair struct {
118 118
 	vstart, vend int
119 119
 }
120 120
 
121
-type byKey struct {
121
+type byKeyVal struct {
122 122
 	sorted bool
123 123
 	json   []byte
124 124
 	pairs  []pair
125 125
 }
126 126
 
127
-func (arr *byKey) Len() int {
127
+func (arr *byKeyVal) Len() int {
128 128
 	return len(arr.pairs)
129 129
 }
130
-func (arr *byKey) Less(i, j int) bool {
130
+func (arr *byKeyVal) Less(i, j int) bool {
131 131
 	key1 := arr.json[arr.pairs[i].kstart+1 : arr.pairs[i].kend-1]
132 132
 	key2 := arr.json[arr.pairs[j].kstart+1 : arr.pairs[j].kend-1]
133
-	return string(key1) < string(key2)
133
+	if string(key1) < string(key2) {
134
+		return true
135
+	}
136
+	if string(key1) > string(key2) {
137
+		return false
138
+	}
139
+	return arr.pairs[i].vstart < arr.pairs[j].vstart
134 140
 }
135
-func (arr *byKey) Swap(i, j int) {
141
+func (arr *byKeyVal) Swap(i, j int) {
136 142
 	arr.pairs[i], arr.pairs[j] = arr.pairs[j], arr.pairs[i]
137 143
 	arr.sorted = true
138 144
 }
@@ -174,7 +180,11 @@ func appendPrettyObject(buf, json []byte, i int, open, close byte, pretty bool,
174 180
 				}
175 181
 				if n > 0 {
176 182
 					nl = len(buf)
177
-					buf = append(buf, '\n')
183
+					if buf[nl-1] == ' ' {
184
+						buf[nl-1] = '\n'
185
+					} else {
186
+						buf = append(buf, '\n')
187
+					}
178 188
 				}
179 189
 				if buf[len(buf)-1] != open {
180 190
 					buf = appendTabs(buf, prefix, indent, tabs)
@@ -193,7 +203,11 @@ func appendPrettyObject(buf, json []byte, i int, open, close byte, pretty bool,
193 203
 			var p pair
194 204
 			if pretty {
195 205
 				nl = len(buf)
196
-				buf = append(buf, '\n')
206
+				if buf[nl-1] == ' ' {
207
+					buf[nl-1] = '\n'
208
+				} else {
209
+					buf = append(buf, '\n')
210
+				}
197 211
 				if open == '{' && sortkeys {
198 212
 					p.kstart = i
199 213
 					p.vstart = len(buf)
@@ -235,8 +249,8 @@ func sortPairs(json, buf []byte, pairs []pair) []byte {
235 249
 	}
236 250
 	vstart := pairs[0].vstart
237 251
 	vend := pairs[len(pairs)-1].vend
238
-	arr := byKey{false, json, pairs}
239
-	sort.Sort(&arr)
252
+	arr := byKeyVal{false, json, pairs}
253
+	sort.Stable(&arr)
240 254
 	if !arr.sorted {
241 255
 		return buf
242 256
 	}
@@ -305,6 +319,7 @@ func appendTabs(buf []byte, prefix, indent string, tabs int) []byte {
305 319
 type Style struct {
306 320
 	Key, String, Number [2]string
307 321
 	True, False, Null   [2]string
322
+	Escape              [2]string
308 323
 	Append              func(dst []byte, c byte) []byte
309 324
 }
310 325
 
@@ -328,6 +343,7 @@ func init() {
328 343
 		True:   [2]string{"\x1B[96m", "\x1B[0m"},
329 344
 		False:  [2]string{"\x1B[96m", "\x1B[0m"},
330 345
 		Null:   [2]string{"\x1B[91m", "\x1B[0m"},
346
+		Escape: [2]string{"\x1B[35m", "\x1B[0m"},
331 347
 		Append: func(dst []byte, c byte) []byte {
332 348
 			if c < ' ' && (c != '\r' && c != '\n' && c != '\t' && c != '\v') {
333 349
 				dst = append(dst, "\\u00"...)
@@ -367,8 +383,39 @@ func Color(src []byte, style *Style) []byte {
367 383
 				dst = append(dst, style.String[0]...)
368 384
 			}
369 385
 			dst = apnd(dst, '"')
386
+			esc := false
387
+			uesc := 0
370 388
 			for i = i + 1; i < len(src); i++ {
371
-				dst = apnd(dst, src[i])
389
+				if src[i] == '\\' {
390
+					if key {
391
+						dst = append(dst, style.Key[1]...)
392
+					} else {
393
+						dst = append(dst, style.String[1]...)
394
+					}
395
+					dst = append(dst, style.Escape[0]...)
396
+					dst = apnd(dst, src[i])
397
+					esc = true
398
+					if i+1 < len(src) && src[i+1] == 'u' {
399
+						uesc = 5
400
+					} else {
401
+						uesc = 1
402
+					}
403
+				} else if esc {
404
+					dst = apnd(dst, src[i])
405
+					if uesc == 1 {
406
+						esc = false
407
+						dst = append(dst, style.Escape[1]...)
408
+						if key {
409
+							dst = append(dst, style.Key[0]...)
410
+						} else {
411
+							dst = append(dst, style.String[0]...)
412
+						}
413
+					} else {
414
+						uesc--
415
+					}
416
+				} else {
417
+					dst = apnd(dst, src[i])
418
+				}
372 419
 				if src[i] == '"' {
373 420
 					j := i - 1
374 421
 					for ; ; j-- {
@@ -381,7 +428,9 @@ func Color(src []byte, style *Style) []byte {
381 428
 					}
382 429
 				}
383 430
 			}
384
-			if key {
431
+			if esc {
432
+				dst = append(dst, style.Escape[1]...)
433
+			} else if key {
385 434
 				dst = append(dst, style.Key[1]...)
386 435
 			} else {
387 436
 				dst = append(dst, style.String[1]...)
@@ -434,3 +483,90 @@ func Color(src []byte, style *Style) []byte {
434 483
 	}
435 484
 	return dst
436 485
 }
486
+
487
+// Spec strips out comments and trailing commas and convert the input to a
488
+// valid JSON per the official spec: https://tools.ietf.org/html/rfc8259
489
+//
490
+// The resulting JSON will always be the same length as the input and it will
491
+// include all of the same line breaks at matching offsets. This is to ensure
492
+// the result can be later processed by a external parser and that that
493
+// parser will report messages or errors with the correct offsets.
494
+func Spec(src []byte) []byte {
495
+	return spec(src, nil)
496
+}
497
+
498
+// SpecInPlace is the same as Spec, but this method reuses the input json
499
+// buffer to avoid allocations. Do not use the original bytes slice upon return.
500
+func SpecInPlace(src []byte) []byte {
501
+	return spec(src, src)
502
+}
503
+
504
+func spec(src, dst []byte) []byte {
505
+	dst = dst[:0]
506
+	for i := 0; i < len(src); i++ {
507
+		if src[i] == '/' {
508
+			if i < len(src)-1 {
509
+				if src[i+1] == '/' {
510
+					dst = append(dst, ' ', ' ')
511
+					i += 2
512
+					for ; i < len(src); i++ {
513
+						if src[i] == '\n' {
514
+							dst = append(dst, '\n')
515
+							break
516
+						} else if src[i] == '\t' || src[i] == '\r' {
517
+							dst = append(dst, src[i])
518
+						} else {
519
+							dst = append(dst, ' ')
520
+						}
521
+					}
522
+					continue
523
+				}
524
+				if src[i+1] == '*' {
525
+					dst = append(dst, ' ', ' ')
526
+					i += 2
527
+					for ; i < len(src)-1; i++ {
528
+						if src[i] == '*' && src[i+1] == '/' {
529
+							dst = append(dst, ' ', ' ')
530
+							i++
531
+							break
532
+						} else if src[i] == '\n' || src[i] == '\t' ||
533
+							src[i] == '\r' {
534
+							dst = append(dst, src[i])
535
+						} else {
536
+							dst = append(dst, ' ')
537
+						}
538
+					}
539
+					continue
540
+				}
541
+			}
542
+		}
543
+		dst = append(dst, src[i])
544
+		if src[i] == '"' {
545
+			for i = i + 1; i < len(src); i++ {
546
+				dst = append(dst, src[i])
547
+				if src[i] == '"' {
548
+					j := i - 1
549
+					for ; ; j-- {
550
+						if src[j] != '\\' {
551
+							break
552
+						}
553
+					}
554
+					if (j-i)%2 != 0 {
555
+						break
556
+					}
557
+				}
558
+			}
559
+		} else if src[i] == '}' || src[i] == ']' {
560
+			for j := len(dst) - 2; j >= 0; j-- {
561
+				if dst[j] <= ' ' {
562
+					continue
563
+				}
564
+				if dst[j] == ',' {
565
+					dst[j] = ' '
566
+				}
567
+				break
568
+			}
569
+		}
570
+	}
571
+	return dst
572
+}

vendor/github.com/tidwall/rtree/LICENSE → vendor/github.com/tidwall/rtred/LICENSE View File


vendor/github.com/tidwall/rtree/README.md → vendor/github.com/tidwall/rtred/README.md View File

@@ -1,7 +1,6 @@
1 1
 RTree implementation for Go
2 2
 ===========================
3 3
 
4
-[![Build Status](https://travis-ci.org/tidwall/rtree.svg?branch=master)](https://travis-ci.org/tidwall/rtree)
5 4
 [![GoDoc](https://godoc.org/github.com/tidwall/rtree?status.svg)](https://godoc.org/github.com/tidwall/rtree)
6 5
 
7 6
 This package provides an in-memory R-Tree implementation for Go, useful as a spatial data structure.

vendor/github.com/tidwall/rtree/base/knn.go → vendor/github.com/tidwall/rtred/base/knn.go View File


vendor/github.com/tidwall/rtree/base/load.go → vendor/github.com/tidwall/rtred/base/load.go View File


vendor/github.com/tidwall/rtree/base/rtree.go → vendor/github.com/tidwall/rtred/base/rtree.go View File


+ 5
- 0
vendor/github.com/tidwall/rtred/go.mod View File

@@ -0,0 +1,5 @@
1
+module github.com/tidwall/rtred
2
+
3
+go 1.15
4
+
5
+require github.com/tidwall/tinyqueue v0.1.1

+ 2
- 0
vendor/github.com/tidwall/rtred/go.sum View File

@@ -0,0 +1,2 @@
1
+github.com/tidwall/tinyqueue v0.1.1 h1:SpNEvEggbpyN5DIReaJ2/1ndroY8iyEGxPYxoSaymYE=
2
+github.com/tidwall/tinyqueue v0.1.1/go.mod h1:O/QNHwrnjqr6IHItYrzoHAKYhBkLI67Q096fQP5zMYw=

vendor/github.com/tidwall/rtree/rtree.go → vendor/github.com/tidwall/rtred/rtree.go View File

@@ -1,10 +1,10 @@
1
-package rtree
1
+package rtred
2 2
 
3 3
 import (
4 4
 	"math"
5 5
 	"sync"
6 6
 
7
-	"github.com/tidwall/rtree/base"
7
+	"github.com/tidwall/rtred/base"
8 8
 )
9 9
 
10 10
 type Iterator func(item Item) bool

+ 0
- 1
vendor/github.com/tidwall/rtree/.travis.yml View File

@@ -1 +0,0 @@
1
-language: go

+ 3
- 0
vendor/github.com/tidwall/tinyqueue/go.mod View File

@@ -0,0 +1,3 @@
1
+module github.com/tidwall/tinyqueue
2
+
3
+go 1.15

+ 11
- 9
vendor/modules.txt View File

@@ -39,23 +39,25 @@ github.com/oragono/confusables
39 39
 github.com/oragono/go-ident
40 40
 # github.com/stretchr/testify v1.4.0
41 41
 ## explicit
42
-# github.com/tidwall/btree v0.2.2
42
+# github.com/tidwall/btree v0.4.2
43 43
 github.com/tidwall/btree
44
-# github.com/tidwall/buntdb v1.1.4
44
+# github.com/tidwall/buntdb v1.2.3
45 45
 ## explicit
46 46
 github.com/tidwall/buntdb
47
-# github.com/tidwall/gjson v1.6.1
47
+# github.com/tidwall/gjson v1.7.4
48 48
 github.com/tidwall/gjson
49
-# github.com/tidwall/grect v0.0.0-20161006141115-ba9a043346eb
49
+# github.com/tidwall/grect v0.1.1
50 50
 github.com/tidwall/grect
51
-# github.com/tidwall/match v1.0.1
51
+# github.com/tidwall/match v1.0.3
52 52
 github.com/tidwall/match
53
-# github.com/tidwall/pretty v1.0.2
53
+# github.com/tidwall/pretty v1.1.0
54 54
 github.com/tidwall/pretty
55
+# github.com/tidwall/rtred v0.1.2
56
+github.com/tidwall/rtred
57
+github.com/tidwall/rtred/base
55 58
 # github.com/tidwall/rtree v0.0.0-20201027154624-32188eeb08a8
56
-github.com/tidwall/rtree
57
-github.com/tidwall/rtree/base
58
-# github.com/tidwall/tinyqueue v0.0.0-20180302190814-1e39f5511563
59
+## explicit
60
+# github.com/tidwall/tinyqueue v0.1.1
59 61
 github.com/tidwall/tinyqueue
60 62
 # github.com/toorop/go-dkim v0.0.0-20201103131630-e1cd1a0a5208
61 63
 ## explicit

Loading…
Cancel
Save