Skip to content

Commit 8a06bc1

Browse files
committed
⭐ New DB caching engine (beta!)
1 parent 4312ace commit 8a06bc1

File tree

3 files changed

+63
-1
lines changed

3 files changed

+63
-1
lines changed

db/_db_caching

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
function _forceCaching(fn) {
2+
var cacheStore = {};
3+
4+
return function() {
5+
var args = Array.prototype.slice.call(arguments),
6+
key = JSON.stringify(args);
7+
8+
if (cacheStore.hasOwnProperty(key)) {
9+
return cacheStore[key];
10+
}
11+
12+
return cacheStore[key] = fn.apply(this, arguments);
13+
};
14+
}
15+
16+
17+
var useBetaDieEngineCachingTechology = true;
18+
19+
if (useBetaDieEngineCachingTechology) {
20+
var classNames = [
21+
"Amiga", "APK", "Archive", "Binary", "COM", "DEX", "DOS4G", "DOS16M",
22+
"ELF", "IPA", "JAR", "LE", "LX", "MACH", "MACHOFAT", "MSDOS", "NE", "NPM", "PDF", "PE", "ZIP"
23+
];
24+
25+
var methodsToWrap = [
26+
"isSignaturePresent",
27+
"isSignatureInSectionPresent",
28+
"findSignature",
29+
"compare",
30+
"findString"
31+
];
32+
33+
for (var i = 0; i < classNames.length; i++) {
34+
var className = classNames[i];
35+
36+
try {
37+
if (typeof this[className] === "object" || typeof this[className] === "function") {
38+
var cls = this[className];
39+
40+
for (var j = 0; j < methodsToWrap.length; j++) {
41+
var methodName = methodsToWrap[j];
42+
if (typeof cls[methodName] === "function") {
43+
cls[methodName] = _forceCaching(cls[methodName]);
44+
}
45+
}
46+
}
47+
} catch (e) {
48+
_error(e.message);
49+
}
50+
}
51+
52+
try {
53+
if (typeof this.PE !== "undefined" && typeof this.PE.isNetObjectPresent === "function") {
54+
this.PE.isNetObjectPresent = _forceCaching(this.PE.isNetObjectPresent);
55+
}
56+
} catch (e) {
57+
_error(e.message);
58+
}
59+
}

db/_debug

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
// Just a debug function
99
function _debug(messageText) {
10+
messageText = "-> " + messageText;
11+
_log("Debug: " + messageText);
1012
_setResult("dev-output", messageText, "", "");
1113
}
1214

db/_init

+2-1
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,5 @@ Number.prototype.padStart = function(targetLength, padString) {
146146
return padString.slice(0, targetLength) + s;
147147
}
148148

149-
includeScript("language");
149+
includeScript("language");
150+
includeScript("_db_caching");

0 commit comments

Comments
 (0)