Merge pull request #850 from fourplusone/feature/remove_opt
CodeCleanup: remove unused _opt in favor of code size/readability
This commit is contained in:
commit
beb6378656
|
@ -27,8 +27,6 @@
|
||||||
|
|
||||||
var AttributePool = require("./AttributePool");
|
var AttributePool = require("./AttributePool");
|
||||||
|
|
||||||
var _opt = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ==================== General Util Functions =======================
|
* ==================== General Util Functions =======================
|
||||||
*/
|
*/
|
||||||
|
@ -127,22 +125,13 @@ exports.opIterator = function (opsStr, optStartIndex) {
|
||||||
function nextRegexMatch() {
|
function nextRegexMatch() {
|
||||||
prevIndex = curIndex;
|
prevIndex = curIndex;
|
||||||
var result;
|
var result;
|
||||||
if (_opt) {
|
|
||||||
result = _opt.nextOpInString(opsStr, curIndex);
|
|
||||||
if (result) {
|
|
||||||
if (result.opcode() == '?') {
|
|
||||||
exports.error("Hit error opcode in op stream");
|
|
||||||
}
|
|
||||||
curIndex = result.lastIndex();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
regex.lastIndex = curIndex;
|
regex.lastIndex = curIndex;
|
||||||
result = regex.exec(opsStr);
|
result = regex.exec(opsStr);
|
||||||
curIndex = regex.lastIndex;
|
curIndex = regex.lastIndex;
|
||||||
if (result[0] == '?') {
|
if (result[0] == '?') {
|
||||||
exports.error("Hit error opcode in op stream");
|
exports.error("Hit error opcode in op stream");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
var regexResult = nextRegexMatch();
|
var regexResult = nextRegexMatch();
|
||||||
|
@ -150,13 +139,7 @@ exports.opIterator = function (opsStr, optStartIndex) {
|
||||||
|
|
||||||
function next(optObj) {
|
function next(optObj) {
|
||||||
var op = (optObj || obj);
|
var op = (optObj || obj);
|
||||||
if (_opt && regexResult) {
|
if (regexResult[0]) {
|
||||||
op.attribs = regexResult.attribs();
|
|
||||||
op.lines = regexResult.lines();
|
|
||||||
op.chars = regexResult.chars();
|
|
||||||
op.opcode = regexResult.opcode();
|
|
||||||
regexResult = nextRegexMatch();
|
|
||||||
} else if ((!_opt) && regexResult[0]) {
|
|
||||||
op.attribs = regexResult[1];
|
op.attribs = regexResult[1];
|
||||||
op.lines = exports.parseNum(regexResult[2] || 0);
|
op.lines = exports.parseNum(regexResult[2] || 0);
|
||||||
op.opcode = regexResult[3];
|
op.opcode = regexResult[3];
|
||||||
|
@ -169,7 +152,7 @@ exports.opIterator = function (opsStr, optStartIndex) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function hasNext() {
|
function hasNext() {
|
||||||
return !!(_opt ? regexResult : regexResult[0]);
|
return !!(regexResult[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function lastIndex() {
|
function lastIndex() {
|
||||||
|
@ -414,34 +397,7 @@ exports.smartOpAssembler = function () {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
if (_opt) {
|
|
||||||
exports.mergingOpAssembler = function () {
|
|
||||||
var assem = _opt.mergingOpAssembler();
|
|
||||||
|
|
||||||
function append(op) {
|
|
||||||
assem.append(op.opcode, op.chars, op.lines, op.attribs);
|
|
||||||
}
|
|
||||||
|
|
||||||
function toString() {
|
|
||||||
return assem.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
function clear() {
|
|
||||||
assem.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
function endDocument() {
|
|
||||||
assem.endDocument();
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
append: append,
|
|
||||||
toString: toString,
|
|
||||||
clear: clear,
|
|
||||||
endDocument: endDocument
|
|
||||||
};
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
exports.mergingOpAssembler = function () {
|
exports.mergingOpAssembler = function () {
|
||||||
// This assembler can be used in production; it efficiently
|
// This assembler can be used in production; it efficiently
|
||||||
// merges consecutive operations that are mergeable, ignores
|
// merges consecutive operations that are mergeable, ignores
|
||||||
|
@ -515,31 +471,9 @@ if (_opt) {
|
||||||
endDocument: endDocument
|
endDocument: endDocument
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
if (_opt) {
|
|
||||||
exports.opAssembler = function () {
|
|
||||||
var assem = _opt.opAssembler();
|
|
||||||
// this function allows op to be mutated later (doesn't keep a ref)
|
|
||||||
|
|
||||||
function append(op) {
|
|
||||||
assem.append(op.opcode, op.chars, op.lines, op.attribs);
|
|
||||||
}
|
|
||||||
|
|
||||||
function toString() {
|
|
||||||
return assem.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
function clear() {
|
|
||||||
assem.clear();
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
append: append,
|
|
||||||
toString: toString,
|
|
||||||
clear: clear
|
|
||||||
};
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
exports.opAssembler = function () {
|
exports.opAssembler = function () {
|
||||||
var pieces = [];
|
var pieces = [];
|
||||||
// this function allows op to be mutated later (doesn't keep a ref)
|
// this function allows op to be mutated later (doesn't keep a ref)
|
||||||
|
@ -566,7 +500,6 @@ if (_opt) {
|
||||||
clear: clear
|
clear: clear
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A custom made String Iterator
|
* A custom made String Iterator
|
||||||
|
|
Loading…
Reference in New Issue