This commit is contained in:
Mariusz Nowak
2013-08-07 22:40:53 +02:00
parent d8136b32c8
commit b0ad851327
8 changed files with 83 additions and 152 deletions

61
.lint
View File

@@ -1,60 +1,35 @@
@root
jslint_medikoo.indent 2
jslint_medikoo.maxlen 80
module
es5
jslint_medikoo.tabs
jslint_medikoo.module
jslint_medikoo.plusplus
jslint_medikoo.nomen
indent 2
maxlen 80
tabs
jshint.laxcomma
jshint.camelcase
jshint.eqeqeq
jshint.forin
jshint.immed
jshint.latedef
jshint.newcap
jshint.noarg
jshint.noempty
jshint.nonew
jshint.regexp
jshint.undef
jshint.unused
jshint.strict
jshint.trailing
jshint.globalstrict
jshint.global module, require, exports
jshint.smarttabs
jshint.eqnull
jshint.expr
ass
plusplus
nomen
./lib/_base.js
jslint_medikoo.bitwise
bitwise
./lib/ext/max-age.js
jslint_medikoo.bitwise
jslint_medikoo.predef+ setTimeout, clearTimeout
jshint.global+ setTimeout, clearTimeout
bitwise
predef+ setTimeout, clearTimeout
./lib/ext/max.js
jslint_medikoo.bitwise
jslint_medikoo.continue
jslint_medikoo.predef+ setTimeout, clearTimeout
jshint.global+ setTimeout, clearTimeout
!jshint.curly
bitwise
continue
predef+ setTimeout, clearTimeout
./test/index.js
jslint_medikoo.predef+ setTimeout
jshint.global+ setTimeout
predef+ setTimeout
./test/ext/max-age.js
jslint_medikoo.predef+ setTimeout
jshint.global+ setTimeout
predef+ setTimeout
./benchmark
jslint_medikoo.sub
jshint.sub
jslint_medikoo.predef+ console
jshint.global+ console
sub
predef+ console

View File

@@ -79,12 +79,9 @@ require('../_base').ext.async = function (ignore, conf) {
fn = conf.memoized;
resolver = function (args) {
cb = last.call(args);
if (isCallable(cb)) {
return slice.call(args, 0, -1);
} else {
cb = null;
return args;
}
if (isCallable(cb)) return slice.call(args, 0, -1);
cb = null;
return args;
};
conf.memoized = function () {
return fn.apply(initContext = this, initArgs = resolver(arguments));

View File

@@ -36,9 +36,9 @@ require('../_base').ext.profile = ext = function (conf) {
ext.force = true;
exports.log = function () {
var initial, cached, time, ordered, ipad, cpad, ppad, toPrc, log;
var initial, cached, ordered, ipad, cpad, ppad, toPrc, log;
initial = cached = time = 0;
initial = cached = 0;
ordered = [];
toPrc = function (initial, cached) {

View File

@@ -20,7 +20,9 @@ require('../_base').ext.resolvers = function (resolvers, conf) {
var resolver;
resolver = toArray(resolvers);
resolver.forEach(function (r) { (r == null) || callable(r); });
resolver.forEach(function (r) {
((r == null) || callable(r));
});
resolver = resolve.bind(resolver);
(function (fn) {

View File

@@ -47,37 +47,35 @@ module.exports = require('./_base')(function (conf, length, options) {
conf.memoized = (length === 1) ? function (id) {
var value;
if (cache.hasOwnProperty(id)) {
hitListeners && conf.emit('hit', id, arguments, this);
if (hitListeners) conf.emit('hit', id, arguments, this);
return cache[id];
} else {
if (arguments.length === 1) value = call.call(fn, this, id);
else value = apply.call(fn, this, arguments);
if (cache.hasOwnProperty(id)) {
throw new CustomError("Circular invocation", 'CIRCULAR_INVOCATION');
}
cache[id] = value;
initListeners && conf.emit('init', id);
return value;
}
if (arguments.length === 1) value = call.call(fn, this, id);
else value = apply.call(fn, this, arguments);
if (cache.hasOwnProperty(id)) {
throw new CustomError("Circular invocation", 'CIRCULAR_INVOCATION');
}
cache[id] = value;
if (initListeners) conf.emit('init', id);
return value;
} : function () {
var id = get(arguments), value;
if (cache.hasOwnProperty(id)) {
hitListeners && conf.emit('hit', id, arguments, this);
if (hitListeners) conf.emit('hit', id, arguments, this);
return cache[id];
} else {
value = apply.call(conf.fn, this, arguments);
if (cache.hasOwnProperty(id)) {
throw new CustomError("Circular invocation", 'CIRCULAR_INVOCATION');
}
cache[id] = value;
initListeners && conf.emit('init', id);
return value;
}
value = apply.call(conf.fn, this, arguments);
if (cache.hasOwnProperty(id)) {
throw new CustomError("Circular invocation", 'CIRCULAR_INVOCATION');
}
cache[id] = value;
if (initListeners) conf.emit('init', id);
return value;
};
conf.clear = function (id) {
if (cache.hasOwnProperty(id)) {
purgeListeners && conf.emit('purge', id);
if (purgeListeners) conf.emit('purge', id);
delete cache[id];
}
};

View File

@@ -69,9 +69,8 @@ module.exports = require('./_base')(function (conf, length) {
argsCache = {};
get = conf.get = function (args) {
var index = 0, set = map, i, length = args.length;
if (length === 0) {
return set[length] || null;
} else if ((set = set[length])) {
if (length === 0) return set[length] || null;
if ((set = set[length])) {
while (index < (length - 1)) {
i = indexOf.call(set[0], args[index]);
if (i === -1) return null;
@@ -217,23 +216,22 @@ module.exports = require('./_base')(function (conf, length) {
conf.memoized = function () {
var id = get(arguments), value;
if (id != null) {
hitListeners && conf.emit('hit', id, arguments, this);
if (hitListeners) conf.emit('hit', id, arguments, this);
return cache[id];
} else {
value = apply.call(fn, this, arguments);
id = get(arguments);
if (id != null) {
throw new CustomError("Circular invocation", 'CIRCULAR_INVOCATION');
}
id = set(arguments);
cache[id] = value;
initListeners && conf.emit('init', id);
return value;
}
value = apply.call(fn, this, arguments);
id = get(arguments);
if (id != null) {
throw new CustomError("Circular invocation", 'CIRCULAR_INVOCATION');
}
id = set(arguments);
cache[id] = value;
if (initListeners) conf.emit('init', id);
return value;
};
conf.clear = function (id) {
if (cache.hasOwnProperty(id)) {
purgeListeners && conf.emit('purge', id);
if (purgeListeners) conf.emit('purge', id);
clear(id);
delete cache[id];
}

View File

@@ -7,11 +7,8 @@ module.exports = function () {
return {
"Regular": {
"Sync": function (a) {
var mfn, fn, i = 0, value = [], x, invoked;
fn = function (x, y) {
++i;
return x + y;
};
var mfn, fn, value = [], x, invoked;
fn = function (x, y) { return x + y; };
mfn = memoize(fn, { dispose: function (val) { value.push(val); } });
mfn(3, 7);
@@ -42,11 +39,8 @@ module.exports = function () {
a(invoked, x, "No args: Pre clear");
},
"Method": function (a) {
var fn, i = 0, value = [];
fn = function (x, y) {
++i;
return x + y;
};
var fn, value = [];
fn = function (x, y) { return x + y; };
Object.defineProperties(value, memoize(fn, {
method: 'mfn',
dispose: function (val) { this.push(val); }
@@ -68,11 +62,8 @@ module.exports = function () {
a.deep(value, [10, 88], "Clear all");
},
"Ref counter": function (a) {
var mfn, fn, i = 0, value = [];
fn = function (x, y) {
++i;
return x + y;
};
var mfn, fn, value = [];
fn = function (x, y) { return x + y; };
mfn = memoize(fn, { refCounter: true,
dispose: function (val) { value.push(val); } });
@@ -95,12 +86,9 @@ module.exports = function () {
a.deep(value, [10, 88], "Clear all");
},
"Async": function (a, d) {
var mfn, fn, u = {}, i = 0, value = [];
var mfn, fn, u = {}, value = [];
fn = function (x, y, cb) {
nextTick(function () {
++i;
cb(null, x + y);
});
nextTick(function () { cb(null, x + y); });
return u;
};
@@ -130,11 +118,8 @@ module.exports = function () {
},
"Primitive": {
"Sync": function (a) {
var mfn, fn, i = 0, value = [];
fn = function (x, y) {
++i;
return x + y;
};
var mfn, fn, value = [];
fn = function (x, y) { return x + y; };
mfn = memoize(fn, { dispose: function (val) { value.push(val); } });
mfn(3, 7);
@@ -153,11 +138,8 @@ module.exports = function () {
a.deep(value, [10, 88], "Clear all");
},
"Ref counter": function (a) {
var mfn, fn, i = 0, value = [];
fn = function (x, y) {
++i;
return x + y;
};
var mfn, fn, value = [];
fn = function (x, y) { return x + y; };
mfn = memoize(fn, { refCounter: true,
dispose: function (val) { value.push(val); } });
@@ -180,12 +162,9 @@ module.exports = function () {
a.deep(value, [10, 88], "Clear all");
},
"Async": function (a, d) {
var mfn, fn, u = {}, i = 0, value = [];
var mfn, fn, u = {}, value = [];
fn = function (x, y, cb) {
nextTick(function () {
++i;
cb(null, x + y);
});
nextTick(function () { cb(null, x + y); });
return u;
};

View File

@@ -1226,11 +1226,8 @@ module.exports = function (t, a) {
"Dispose": {
"Regular": {
"Sync": function (a) {
var mfn, fn, i = 0, value = [], x, invoked;
fn = function (x, y) {
++i;
return x + y;
};
var mfn, fn, value = [], x, invoked;
fn = function (x, y) { return x + y; };
mfn = t(fn, { dispose: function (val) { value.push(val); } });
mfn(3, 7);
@@ -1261,11 +1258,8 @@ module.exports = function (t, a) {
a(invoked, x, "No args: Pre clear");
},
"Ref counter": function (a) {
var mfn, fn, i = 0, value = [];
fn = function (x, y) {
++i;
return x + y;
};
var mfn, fn, value = [];
fn = function (x, y) { return x + y; };
mfn = t(fn, { refCounter: true,
dispose: function (val) { value.push(val); } });
@@ -1288,12 +1282,9 @@ module.exports = function (t, a) {
a.deep(value, [10, 88], "Clear all");
},
"Async": function (a, d) {
var mfn, fn, u = {}, i = 0, value = [];
var mfn, fn, u = {}, value = [];
fn = function (x, y, cb) {
nextTick(function () {
++i;
cb(null, x + y);
});
nextTick(function () { cb(null, x + y); });
return u;
};
@@ -1323,11 +1314,8 @@ module.exports = function (t, a) {
},
"Primitive": {
"Sync": function (a) {
var mfn, fn, i = 0, value = [];
fn = function (x, y) {
++i;
return x + y;
};
var mfn, fn, value = [];
fn = function (x, y) { return x + y; };
mfn = t(fn, { dispose: function (val) { value.push(val); } });
mfn(3, 7);
@@ -1346,11 +1334,8 @@ module.exports = function (t, a) {
a.deep(value, [10, 88], "Clear all");
},
"Ref counter": function (a) {
var mfn, fn, i = 0, value = [];
fn = function (x, y) {
++i;
return x + y;
};
var mfn, fn, value = [];
fn = function (x, y) { return x + y; };
mfn = t(fn, { refCounter: true,
dispose: function (val) { value.push(val); } });
@@ -1373,12 +1358,9 @@ module.exports = function (t, a) {
a.deep(value, [10, 88], "Clear all");
},
"Async": function (a, d) {
var mfn, fn, u = {}, i = 0, value = [];
var mfn, fn, u = {}, value = [];
fn = function (x, y, cb) {
nextTick(function () {
++i;
cb(null, x + y);
});
nextTick(function () { cb(null, x + y); });
return u;
};