Skip to content

Commit 7e5816a

Browse files
committed
some work on decode performance. slice seems to be slow.
1 parent e42dbe6 commit 7e5816a

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

lib/decode.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ decode.dictionary = function() {
5757
var dict = {}
5858

5959
while( decode.data[decode.position] !== 0x65 ) {
60-
dict[ decode.next() ] = decode.next()
60+
dict[ decode.bytes() ] = decode.next()
6161
}
6262

6363
decode.position++
@@ -85,26 +85,25 @@ decode.list = function() {
8585
decode.integer = function() {
8686

8787
var end = decode.find( 0x65 )
88-
var number = decode.data.slice( decode.position+1, end )
88+
var number = +decode.data.toString('ascii', decode.position+1, end )
8989

9090
decode.position += end + 1 - decode.position
9191

92-
return +number
92+
return number
9393

9494
}
9595

9696
decode.bytes = function() {
9797

9898
var sep = decode.find( 0x3A )
99-
var length = +decode.data.slice( decode.position, sep ).toString()
100-
var sepl = ++sep + length
101-
var bytes = decode.data.slice( sep, sepl )
99+
var length = +decode.data.toString('ascii', decode.position, sep )
100+
var end = ++sep + length
102101

103-
decode.position += sepl - decode.position
102+
decode.position += end - decode.position
104103

105104
return decode.encoding
106-
? bytes.toString( decode.encoding )
107-
: bytes
105+
? decode.data.toString(decode.encoding, sep, end )
106+
: decode.data.slice( sep, end )
108107

109108
}
110109

0 commit comments

Comments
 (0)