@@ -97,17 +97,6 @@ var INT_CACHE = {};
97
97
*/
98
98
var UINT_CACHE = { } ;
99
99
100
- /**
101
- * Determines if an integer value is cacheable.
102
- * @param {number } value Integer value
103
- * @param {boolean= } unsigned Whether unsigned or not
104
- * @returns {boolean }
105
- * @inner
106
- */
107
- function cacheable ( value , unsigned ) {
108
- return unsigned ? 0 <= ( value >>>= 0 ) && value < 256 : - 128 <= ( value |= 0 ) && value < 128 ;
109
- }
110
-
111
100
/**
112
101
* @param {number } value
113
102
* @param {boolean= } unsigned
@@ -117,7 +106,8 @@ function cacheable(value, unsigned) {
117
106
function fromInt ( value , unsigned ) {
118
107
var obj , cachedObj , cache ;
119
108
if ( unsigned ) {
120
- if ( cache = cacheable ( value >>>= 0 , true ) ) {
109
+ value >>>= 0 ;
110
+ if ( cache = ( 0 <= value && value < 256 ) ) {
121
111
cachedObj = UINT_CACHE [ value ] ;
122
112
if ( cachedObj )
123
113
return cachedObj ;
@@ -127,7 +117,8 @@ function fromInt(value, unsigned) {
127
117
UINT_CACHE [ value ] = obj ;
128
118
return obj ;
129
119
} else {
130
- if ( cache = cacheable ( value |= 0 , false ) ) {
120
+ value |= 0 ;
121
+ if ( cache = ( - 128 <= value && value < 128 ) ) {
131
122
cachedObj = INT_CACHE [ value ] ;
132
123
if ( cachedObj )
133
124
return cachedObj ;
@@ -192,15 +183,6 @@ Long.fromNumber = fromNumber;
192
183
* @inner
193
184
*/
194
185
function fromBits ( lowBits , highBits , unsigned ) {
195
- //? if (DISPOSE) {
196
- if ( disposed . length > 0 ) {
197
- var inst = disposed . shift ( ) ;
198
- inst . low = lowBits | 0 ;
199
- inst . high = highBits | 0 ;
200
- inst . unsigned = ! ! unsigned ;
201
- return inst ;
202
- }
203
- //? }
204
186
return new Long ( lowBits , highBits , unsigned ) ;
205
187
}
206
188
@@ -307,61 +289,6 @@ function fromValue(val) {
307
289
* @expose
308
290
*/
309
291
Long . fromValue = fromValue ;
310
- //? if (DISPOSE) {
311
-
312
- // This is experimental code that will probably be removed in the future. At first glance something like this can seem
313
- // reasonable, but it would require a lot of additional (possibly MetaScript) code to perform disposal of intermediate
314
- // values everywhere. Otherwise, calling dispose as a user would not have much of an effect as any manually disposed
315
- // instances become reused a lot faster internally than a user can provide more. After testing this out for a bit I am
316
- // not convinced that the additional overhead from calling dispose() on literally every intermediate instance is worth
317
- // it.
318
- //
319
- // Alternatively, it has been suggested to add self-mutating methods in #24, but this would also be neglected by the
320
- // sheer number of intermediate instances that are still necessary.
321
- //
322
- // On this basis I'd recommend not to implement anything of this and leave memory optimization efforts to the VM.
323
- // -dcode
324
-
325
- /**
326
- * Disposed Longs.
327
- * @type {!Array.<!Long> }
328
- * @inner
329
- */
330
- var disposed = [ ] ;
331
-
332
- /**
333
- * @param {!Long } inst
334
- * @returns {boolean }
335
- * @inner
336
- */
337
- function dispose ( inst ) {
338
- if ( disposed . length > 1023 )
339
- return false ;
340
- if ( ! ( inst /* compatible */ instanceof Long ) )
341
- return false ;
342
- // Do not dispose if cached
343
- if ( inst . unsigned ) {
344
- if ( inst . high == 0 && UINT_CACHE [ inst . low >>> 0 ] === inst )
345
- return false ;
346
- } else {
347
- if ( ( inst . high == 0 || inst . high == - 1 ) && INT_CACHE [ inst . low ] === inst )
348
- return false ;
349
- }
350
- disposed . push ( inst ) ;
351
- return true ;
352
- }
353
-
354
- /**
355
- * Disposes a Long instance and queues it for reuse. If not ultimately necessary, it is recommended not to use this
356
- * method at all. If used however, it must be guaranteed that a disposed instance is never used again and that this
357
- * method is never called more than once with the same instance.
358
- * @function
359
- * @param {!Long } inst Long instance to dispose
360
- * @returns {boolean } Whether actually disposed
361
- * @expose
362
- */
363
- Long . dispose = dispose ;
364
- //? }
365
292
366
293
// NOTE: the compiler should inline these constant values below and then remove these variables, so there should be
367
294
// no runtime penalty for these.
0 commit comments