@@ -69,20 +69,20 @@ const encodeUtf8 = hasNodeBuffer ? function(target, string, position) {
69
69
const TYPE = Symbol ( 'type' ) ;
70
70
const PARENT = Symbol ( 'parent' ) ;
71
71
setWriteStructSlots ( writeStruct , prepareStructures ) ;
72
- function writeStruct ( object , target , position , structures , makeRoom , pack , packr ) {
72
+ function writeStruct ( object , target , encodingStart , position , structures , makeRoom , pack , packr ) {
73
73
let typedStructs = packr . typedStructs || ( packr . typedStructs = [ ] ) ;
74
74
// note that we rely on pack.js to load stored structures before we get to this point
75
75
let targetView = target . dataView ;
76
76
let refsStartPosition = ( typedStructs . lastStringStart || 100 ) + position ;
77
77
let safeEnd = target . length - 10 ;
78
78
let start = position ;
79
79
if ( position > safeEnd ) {
80
- let lastStart = start ;
81
80
target = makeRoom ( position ) ;
82
81
targetView = target . dataView ;
83
- position -= lastStart ;
84
- refsStartPosition -= lastStart ;
85
- start = 0 ;
82
+ position -= encodingStart ;
83
+ start -= encodingStart ;
84
+ refsStartPosition -= encodingStart ;
85
+ encodingStart = 0 ;
86
86
safeEnd = target . length - 10 ;
87
87
}
88
88
@@ -120,13 +120,13 @@ function writeStruct(object, target, position, structures, makeRoom, pack, packr
120
120
} ;
121
121
}
122
122
if ( position > safeEnd ) {
123
- let lastStart = start ;
124
123
target = makeRoom ( position ) ;
125
124
targetView = target . dataView ;
126
- position -= lastStart ;
127
- refsStartPosition -= lastStart ;
128
- refPosition -= lastStart ;
129
- start = 0 ;
125
+ position -= encodingStart ;
126
+ start -= encodingStart ;
127
+ refsStartPosition -= encodingStart ;
128
+ refPosition -= encodingStart ;
129
+ encodingStart = 0 ;
130
130
safeEnd = target . length - 10
131
131
}
132
132
switch ( typeof value ) {
@@ -165,13 +165,13 @@ function writeStruct(object, target, position, structures, makeRoom, pack, packr
165
165
let strLength = value . length ;
166
166
refOffset = refPosition - refsStartPosition ;
167
167
if ( ( strLength << 2 ) + refPosition > safeEnd ) {
168
- let lastStart = start ;
169
168
target = makeRoom ( ( strLength << 2 ) + refPosition ) ;
170
169
targetView = target . dataView ;
171
- position -= lastStart ;
172
- refsStartPosition -= lastStart ;
173
- refPosition -= lastStart ;
174
- start = 0 ;
170
+ position -= encodingStart ;
171
+ start -= encodingStart ;
172
+ refsStartPosition -= encodingStart ;
173
+ refPosition -= encodingStart ;
174
+ encodingStart = 0 ;
175
175
safeEnd = target . length - 10
176
176
}
177
177
if ( strLength > ( ( 0xff00 + refOffset ) >> 2 ) ) {
@@ -330,9 +330,10 @@ function writeStruct(object, target, position, structures, makeRoom, pack, packr
330
330
refPosition = newPosition . position ;
331
331
targetView = newPosition . targetView ;
332
332
target = newPosition . target ;
333
- refsStartPosition -= start ;
334
- position -= start ;
335
- start = 0 ;
333
+ refsStartPosition -= encodingStart ;
334
+ position -= encodingStart ;
335
+ start -= encodingStart ;
336
+ encodingStart = 0 ;
336
337
} else
337
338
refPosition = newPosition ;
338
339
if ( size === 2 ) {
@@ -406,7 +407,7 @@ function writeStruct(object, target, position, structures, makeRoom, pack, packr
406
407
if ( refsStartPosition === refPosition )
407
408
return position ; // no refs
408
409
typedStructs . lastStringStart = position - start ;
409
- return writeStruct ( object , target , start , structures , makeRoom , pack , packr ) ;
410
+ return writeStruct ( object , target , encodingStart , start , structures , makeRoom , pack , packr ) ;
410
411
}
411
412
return refPosition ;
412
413
}
0 commit comments