Skip to content

Commit 873940d

Browse files
committed
Implement slowEqual speed enhancement from ssbc#128
1 parent 5a5c63c commit 873940d

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

operators.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,11 @@ function toBufferOrFalsy(value) {
3434
function seekFromDesc(desc) {
3535
const keys = desc.split('.')
3636
// The 2nd arg `start` is to support plucks too
37+
const compiledSeek = bipf.createSeekPath(keys)
3738
return (buffer, start = 0) => {
38-
var p = start
39-
for (let key of keys) {
40-
p = bipf.seekKey(buffer, p, Buffer.from(key))
41-
if (!~p) return void 0
42-
}
43-
return p
39+
const p = compiledSeek(buffer, start)
40+
if (!~p) return void 0
41+
else return p
4442
}
4543
}
4644

test/operators.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ prepareAndRunTest('operators API supports slowEqual', dir, (t, db, raf) => {
8989
t.equal(queryTree.data.indexType, 'value_content_type')
9090
t.notOk(queryTree.data.indexAll)
9191
t.deepEqual(queryTree.data.value, Buffer.from('post'))
92-
t.true(queryTree.data.seek.toString().includes('bipf.seekKey'))
92+
t.true(queryTree.data.seek.toString().includes('compiledSeek'))
9393

9494
t.equal(typeof queryTree.meta, 'object', 'queryTree contains meta')
9595
t.equal(
@@ -186,7 +186,7 @@ prepareAndRunTest('slowEqual 3 args', dir, (t, db, raf) => {
186186
t.equal(queryTree.data.indexType, 'value_content_type')
187187
t.equal(queryTree.data.indexAll, true)
188188
t.deepEqual(queryTree.data.value, Buffer.from('post'))
189-
t.true(queryTree.data.seek.toString().includes('bipf.seekKey'))
189+
t.true(queryTree.data.seek.toString().includes('compiledSeek'))
190190

191191
t.end()
192192
})
@@ -253,7 +253,7 @@ prepareAndRunTest('slowEqual with prefix', dir, (t, db, raf) => {
253253

254254
t.equal(queryTree.data.indexType, 'value_content_type')
255255
t.deepEqual(queryTree.data.value, Buffer.from('post'))
256-
t.true(queryTree.data.seek.toString().includes('bipf.seekKey'))
256+
t.true(queryTree.data.seek.toString().includes('compiledSeek'))
257257
t.equal(queryTree.data.prefix, 32)
258258

259259
t.end()
@@ -300,14 +300,14 @@ prepareAndRunTest('operators API supports or()', dir, (t, db, raf) => {
300300
t.deepEqual(queryTree.data[1].data[0].data.indexType, 'value_author')
301301
t.deepEqual(queryTree.data[1].data[0].data.value, Buffer.from(alice.id))
302302
t.true(
303-
queryTree.data[1].data[0].data.seek.toString().includes('bipf.seekKey')
303+
queryTree.data[1].data[0].data.seek.toString().includes('compiledSeek')
304304
)
305305

306306
t.equal(queryTree.data[1].data[1].type, 'EQUAL')
307307
t.equal(queryTree.data[1].data[1].data.indexType, 'value_author')
308308
t.deepEqual(queryTree.data[1].data[1].data.value, Buffer.from(bob.id))
309309
t.true(
310-
queryTree.data[1].data[1].data.seek.toString().includes('bipf.seekKey')
310+
queryTree.data[1].data[1].data.seek.toString().includes('compiledSeek')
311311
)
312312

313313
t.end()

0 commit comments

Comments
 (0)