- Provide easy transparent lazy evaluation pattern with memorization for values itself(not object properties)
` var _fn = function(a, b, c) { var d = new Evaluator(
| /* | |
| Strong implementation must check that key is object, | |
| hide weakMapN_ from enumeration, make it externally readonly and non deletable(Object.defineProperty, if presents), | |
| but its bad for performance. | |
| */ | |
| (function($G) | |
| { | |
| var nextStoreKeyId = 0; | |
| // http://en.wikipedia.org/wiki/Fast_inverse_square_root | |
| /* | |
| Discovering old well known algorithm speed in js. | |
| */ | |
| /* | |
| Update 1 | |
| Added 3rd variant - 1st with removed <y> varable. Hm, it really become more faster. Thanks Andrea! | |
| */ |
| /* | |
| This test detects if engine cache bytecode or not. | |
| */ | |
| var _main = function() | |
| { | |
| var bigCode = String(_main); | |
| bigCode = bigCode.slice(bigCode.indexOf('{') + 1, bigCode.lastIndexOf('}')); | |
| bigCode = new Array(11).join(bigCode); // *= 10 to make really big code |
| enum ValueType | |
| { | |
| NULL, | |
| UNDEFINED, | |
| NUMBER_INT, | |
| NUMBER_DOUBLE, | |
| STRING, |
| String String::slice(Int begin, Int end) | |
| { | |
| String a; | |
| // calculate real begin and end | |
| a.begin = buffer->begin + begin; | |
| a.length = end - begin; | |
| a.buffer = buffer; | |
| buffer->refCount++; |
| Const Value& HashTable::_lookup(Const String& key) | |
| { | |
| int hash = _hash(key); | |
| int p = hash%entriesCount; | |
| while(entries[p].hash == hash && p < entriesCount) | |
| { | |
| if(_stringCompare(entries[p].key, key)) | |
| return entries[p].value; | |
| struct HashTable // Open addressing Hash Table with linear probing | |
| { | |
| int entriesCount; | |
| int id; | |
| HashTableEntry entries[0]; | |
| }; | |
| void HashTable::_set(Const String key, Value& value) | |
| { | |
| // if key is new |
| Object.prototype.__defineGetter__ = function(name, _fn) | |
| { | |
| var self = this; | |
| var _wrapper = function() | |
| { | |
| return _fn.call(self); | |
| }; | |
| this[name] = | |
| { |
| (function($G) | |
| { | |
| var defaultThis = (function(){ return this; })(); | |
| var Vector = function(x, y, z) | |
| { | |
| // cast | |
| if(this === defaultThis) | |
| { | |
| return Vector.prototype._calc(x); |