slightly improved speed with rc4 encoding

This commit is contained in:
sanex3339
2016-12-25 15:00:45 +03:00
parent 1271de0b3a
commit 6aba608f36
2 changed files with 53 additions and 21 deletions
+20 -9
View File
@@ -5852,6 +5852,7 @@ var StringLiteralReplacer = StringLiteralReplacer_1 = function (_AbstractReplace
var _this = (0, _possibleConstructorReturn3.default)(this, (StringLiteralReplacer.__proto__ || (0, _getPrototypeOf2.default)(StringLiteralReplacer)).call(this, options));
_this.stringLiteralCache = new _map2.default();
_this.stringLiteralHexadecimalIndexCache = new _map2.default();
_this.customNodeGroupStorage = customNodeGroupStorage;
_this.stringArrayStorage = stringArrayStorage;
return _this;
@@ -5876,6 +5877,24 @@ var StringLiteralReplacer = StringLiteralReplacer_1 = function (_AbstractReplace
this.stringLiteralCache.set(nodeValue, result);
return result;
}
}, {
key: "getArrayHexadecimalIndex",
value: function getArrayHexadecimalIndex(value) {
if (this.stringLiteralHexadecimalIndexCache.has(value)) {
return this.stringLiteralHexadecimalIndexCache.get(value);
}
var indexOfExistingValue = this.stringArrayStorage.getKeyOf(value);
var indexOfValue = void 0;
if (indexOfExistingValue >= 0) {
indexOfValue = indexOfExistingValue;
} else {
indexOfValue = this.stringArrayStorage.getLength();
this.stringArrayStorage.set(null, value);
}
var hexadecimalIndex = "" + Utils_1.Utils.hexadecimalPrefix + Utils_1.Utils.decToHex(indexOfValue);
this.stringLiteralHexadecimalIndexCache.set(value, hexadecimalIndex);
return hexadecimalIndex;
}
}, {
key: "replaceStringLiteralWithStringArrayCall",
value: function replaceStringLiteralWithStringArrayCall(value) {
@@ -5890,17 +5909,9 @@ var StringLiteralReplacer = StringLiteralReplacer_1 = function (_AbstractReplace
break;
}
value = Utils_1.Utils.stringToUnicodeEscapeSequence(value, !this.options.unicodeEscapeSequence);
var indexOfExistingValue = this.stringArrayStorage.getKeyOf(value);
var indexOfValue = void 0;
if (indexOfExistingValue >= 0) {
indexOfValue = indexOfExistingValue;
} else {
indexOfValue = this.stringArrayStorage.getLength();
this.stringArrayStorage.set(null, value);
}
var hexadecimalIndex = this.getArrayHexadecimalIndex(value);
var rotatedStringArrayStorageId = Utils_1.Utils.stringRotate(this.stringArrayStorage.getStorageId(), 1);
var stringArrayStorageCallsWrapperName = "_" + Utils_1.Utils.hexadecimalPrefix + rotatedStringArrayStorageId;
var hexadecimalIndex = "" + Utils_1.Utils.hexadecimalPrefix + Utils_1.Utils.decToHex(indexOfValue);
if (this.options.stringArrayEncoding === StringArrayEncoding_1.StringArrayEncoding.rc4) {
return stringArrayStorageCallsWrapperName + "('" + hexadecimalIndex + "', '" + Utils_1.Utils.stringToUnicodeEscapeSequence(rc4Key, !this.options.unicodeEscapeSequence) + "')";
}
@@ -30,6 +30,11 @@ export class StringLiteralReplacer extends AbstractReplacer {
*/
private readonly stringLiteralCache: Map <string, string> = new Map();
/**
* @type {Map<string, string>}
*/
private readonly stringLiteralHexadecimalIndexCache: Map <string, string> = new Map();
/**
* @type {IStorage<ICustomNodeGroup>}
*/
@@ -91,6 +96,33 @@ export class StringLiteralReplacer extends AbstractReplacer {
return result;
}
/**
* @param value
* @return {string}
*/
private getArrayHexadecimalIndex (value: string): string {
if (this.stringLiteralHexadecimalIndexCache.has(value)) {
return <string>this.stringLiteralHexadecimalIndexCache.get(value);
}
const indexOfExistingValue: number = <number>this.stringArrayStorage.getKeyOf(value);
let indexOfValue: number;
if (indexOfExistingValue >= 0) {
indexOfValue = indexOfExistingValue;
} else {
indexOfValue = this.stringArrayStorage.getLength();
this.stringArrayStorage.set(null, value);
}
const hexadecimalIndex: string = `${Utils.hexadecimalPrefix}${Utils.decToHex(indexOfValue)}`;
this.stringLiteralHexadecimalIndexCache.set(value, hexadecimalIndex);
return hexadecimalIndex;
}
/**
* @param value
* @returns {string}
@@ -113,20 +145,9 @@ export class StringLiteralReplacer extends AbstractReplacer {
value = Utils.stringToUnicodeEscapeSequence(value, !this.options.unicodeEscapeSequence);
const indexOfExistingValue: number = <number>this.stringArrayStorage.getKeyOf(value);
let indexOfValue: number;
if (indexOfExistingValue >= 0) {
indexOfValue = indexOfExistingValue;
} else {
indexOfValue = this.stringArrayStorage.getLength();
this.stringArrayStorage.set(null, value);
}
const hexadecimalIndex: string = this.getArrayHexadecimalIndex(value);
const rotatedStringArrayStorageId: string = Utils.stringRotate(this.stringArrayStorage.getStorageId(), 1);
const stringArrayStorageCallsWrapperName: string = `_${Utils.hexadecimalPrefix}${rotatedStringArrayStorageId}`;
const hexadecimalIndex: string = `${Utils.hexadecimalPrefix}${Utils.decToHex(indexOfValue)}`;
if (this.options.stringArrayEncoding === StringArrayEncoding.rc4) {
return `${stringArrayStorageCallsWrapperName}('${hexadecimalIndex}', '${Utils.stringToUnicodeEscapeSequence(rc4Key, !this.options.unicodeEscapeSequence)}')`;