Skip to content

Commit

Permalink
Post-merge, pre-publish
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Jan 7, 2016
1 parent 9717c38 commit 27b43e5
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 113 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "long",
"version": "3.0.2",
"version": "3.0.3",
"author": "Daniel Wirtz <[email protected]>",
"description": "A Long class for representing a 64 bit two's-complement integer value.",
"main": "dist/long.js",
Expand Down
17 changes: 4 additions & 13 deletions dist/long.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,6 @@
*/
var UINT_CACHE = {};

/**
* Determines if an integer value is cacheable.
* @param {number} value Integer value
* @param {boolean=} unsigned Whether unsigned or not
* @returns {boolean}
* @inner
*/
function cacheable(value, unsigned) {
return unsigned ? 0 <= (value >>>= 0) && value < 256 : -128 <= (value |= 0) && value < 128;
}

/**
* @param {number} value
* @param {boolean=} unsigned
Expand All @@ -151,7 +140,8 @@
function fromInt(value, unsigned) {
var obj, cachedObj, cache;
if (unsigned) {
if (cache = cacheable(value >>>= 0, true)) {
value >>>= 0;
if (cache = (0 <= value && value < 256)) {
cachedObj = UINT_CACHE[value];
if (cachedObj)
return cachedObj;
Expand All @@ -161,7 +151,8 @@
UINT_CACHE[value] = obj;
return obj;
} else {
if (cache = cacheable(value |= 0, false)) {
value |= 0;
if (cache = (-128 <= value && value < 128)) {
cachedObj = INT_CACHE[value];
if (cachedObj)
return cachedObj;
Expand Down
29 changes: 14 additions & 15 deletions dist/long.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified dist/long.min.js.gz
Binary file not shown.
6 changes: 3 additions & 3 deletions dist/long.min.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "long",
"version": "3.0.2",
"version": "3.0.3",
"author": "Daniel Wirtz <[email protected]>",
"description": "A Long class for representing a 64-bit two's-complement integer value.",
"main": "dist/long.js",
Expand Down
4 changes: 1 addition & 3 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ var rootDir = path.join(__dirname, ".."),
pkg = require(path.join(rootDir, "package.json")),
filename;

var scope = {
DISPOSE: false
};
var scope = {};

// Build
console.log("Building long.js with scope", JSON.stringify(scope, null, 2));
Expand Down
81 changes: 4 additions & 77 deletions src/long.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,6 @@ var INT_CACHE = {};
*/
var UINT_CACHE = {};

/**
* Determines if an integer value is cacheable.
* @param {number} value Integer value
* @param {boolean=} unsigned Whether unsigned or not
* @returns {boolean}
* @inner
*/
function cacheable(value, unsigned) {
return unsigned ? 0 <= (value >>>= 0) && value < 256 : -128 <= (value |= 0) && value < 128;
}

/**
* @param {number} value
* @param {boolean=} unsigned
Expand All @@ -117,7 +106,8 @@ function cacheable(value, unsigned) {
function fromInt(value, unsigned) {
var obj, cachedObj, cache;
if (unsigned) {
if (cache = cacheable(value >>>= 0, true)) {
value >>>= 0;
if (cache = (0 <= value && value < 256)) {
cachedObj = UINT_CACHE[value];
if (cachedObj)
return cachedObj;
Expand All @@ -127,7 +117,8 @@ function fromInt(value, unsigned) {
UINT_CACHE[value] = obj;
return obj;
} else {
if (cache = cacheable(value |= 0, false)) {
value |= 0;
if (cache = (-128 <= value && value < 128)) {
cachedObj = INT_CACHE[value];
if (cachedObj)
return cachedObj;
Expand Down Expand Up @@ -192,15 +183,6 @@ Long.fromNumber = fromNumber;
* @inner
*/
function fromBits(lowBits, highBits, unsigned) {
//? if (DISPOSE) {
if (disposed.length > 0) {
var inst = disposed.shift();
inst.low = lowBits | 0;
inst.high = highBits | 0;
inst.unsigned = !!unsigned;
return inst;
}
//? }
return new Long(lowBits, highBits, unsigned);
}

Expand Down Expand Up @@ -307,61 +289,6 @@ function fromValue(val) {
* @expose
*/
Long.fromValue = fromValue;
//? if (DISPOSE) {

// This is experimental code that will probably be removed in the future. At first glance something like this can seem
// reasonable, but it would require a lot of additional (possibly MetaScript) code to perform disposal of intermediate
// values everywhere. Otherwise, calling dispose as a user would not have much of an effect as any manually disposed
// instances become reused a lot faster internally than a user can provide more. After testing this out for a bit I am
// not convinced that the additional overhead from calling dispose() on literally every intermediate instance is worth
// it.
//
// Alternatively, it has been suggested to add self-mutating methods in #24, but this would also be neglected by the
// sheer number of intermediate instances that are still necessary.
//
// On this basis I'd recommend not to implement anything of this and leave memory optimization efforts to the VM.
// -dcode

/**
* Disposed Longs.
* @type {!Array.<!Long>}
* @inner
*/
var disposed = [];

/**
* @param {!Long} inst
* @returns {boolean}
* @inner
*/
function dispose(inst) {
if (disposed.length > 1023)
return false;
if (!(inst /* compatible */ instanceof Long))
return false;
// Do not dispose if cached
if (inst.unsigned) {
if (inst.high == 0 && UINT_CACHE[inst.low >>> 0] === inst)
return false;
} else {
if ((inst.high == 0 || inst.high == -1) && INT_CACHE[inst.low] === inst)
return false;
}
disposed.push(inst);
return true;
}

/**
* Disposes a Long instance and queues it for reuse. If not ultimately necessary, it is recommended not to use this
* method at all. If used however, it must be guaranteed that a disposed instance is never used again and that this
* method is never called more than once with the same instance.
* @function
* @param {!Long} inst Long instance to dispose
* @returns {boolean} Whether actually disposed
* @expose
*/
Long.dispose = dispose;
//? }

// NOTE: the compiler should inline these constant values below and then remove these variables, so there should be
// no runtime penalty for these.
Expand Down

0 comments on commit 27b43e5

Please sign in to comment.