Permalink
Browse files

version bump 0.6.21: performance

- XLS: eliminated unnecessary binds
- XML: ported performance improvements from js-xlsx
- jscs linting to check for trailing comma issues
- updated SSF to 0.7.1
- updated codepage to 1.2.0
- improved coverage in tests
  • Loading branch information...
1 parent 95b4d64 commit 97781525161fb106fa75100e63dbde7c4f082e43 @SheetJSDev SheetJSDev committed Jun 8, 2014
Showing with 1,560 additions and 1,375 deletions.
  1. +6 −0 .jscs.json
  2. +9 −0 .npmignore
  3. +3 −1 .travis.yml
  4. +7 −1 Makefile
  5. +11 −1 bin/xls.njs
  6. +1 −1 bits/01_version.js
  7. +7 −5 bits/08_blob.js
  8. +26 −9 bits/10_ssf.js
  9. +8 −12 bits/12_parsetypes.js
  10. +4 −3 bits/18_cfb.js
  11. +10 −13 bits/20_parsebits.js
  12. +1 −0 bits/30_jsutils.js
  13. +17 −24 bits/32_bifffunc.js
  14. +14 −6 bits/35_xmlutils.js
  15. +113 −121 bits/80_xls.js
  16. +3 −30 bits/81_xlmlutils.js
  17. +90 −81 bits/84_xlml.js
  18. +2 −0 bits/87_read.js
  19. +437 −426 dist/cpexcel.js
  20. +5 −5 dist/xls.core.min.js
  21. +1 −1 dist/xls.core.min.map
  22. +10 −10 dist/xls.full.min.js
  23. +1 −1 dist/xls.full.min.map
  24. +296 −305 dist/xls.js
  25. +5 −5 dist/xls.min.js
  26. +1 −1 dist/xls.min.map
  27. +136 −0 misc/ssf.json
  28. +6 −5 package.json
  29. +34 −3 test.js
  30. +296 −305 xls.js
View
@@ -0,0 +1,6 @@
+{
+ "requireCommaBeforeLineBreak": true,
+ "disallowTrailingWhitespace": true,
+ "disallowTrailingComma": true
+}
+
View
@@ -1 +1,10 @@
test_files/
+index.html
+misc/
+node_modules
+tmp
+*.xls
+*.xlsb
+*.xlsm
+*.xlsx
+*.xml
View
@@ -1,13 +1,15 @@
language: node_js
node_js:
+ - "0.11"
- "0.10"
- "0.8"
before_install:
- "npm install -g mocha"
- "npm install blanket"
+ - "npm install xlsx"
- "npm install coveralls mocha-lcov-reporter"
before_script:
- "make init"
- - "cd test_files; make; cd .."
+ - "cd test_files; make all; cd -"
after_success:
- "make coveralls-spin"
View
@@ -13,7 +13,11 @@ bits/01_version.js: package.json
.PHONY: clean
clean:
- rm $(TARGET)
+ rm -f $(TARGET)
+
+.PHONY: clean-data
+clean-data:
+ rm -f *.xlsx *.xlsm *.xlsb *.xls *.xml
.PHONY: init
init:
@@ -37,6 +41,8 @@ $(TESTFMT): test_%:
.PHONY: lint
lint: $(TARGET)
jshint --show-non-errors $(TARGET)
+ jscs $(TARGET)
+
.PHONY: cov cov-spin
cov: misc/coverage.html
View
@@ -18,6 +18,8 @@ program
.option('-F, --field-sep <sep>', 'CSV field separator', ",")
.option('-R, --row-sep <sep>', 'CSV row separator', "\n")
.option('-n, --sheet-rows <num>', 'Number of rows to process (0=all rows)')
+ .option('--perf', 'do not generate output')
+ .option('--all', 'parse everything')
.option('--dev', 'development mode')
.option('--read', 'read but do not print out contents')
.option('-q, --quiet', 'quiet mode');
@@ -51,8 +53,14 @@ if(!fs.existsSync(filename)) {
var opts = {}, wb;
if(program.listSheets) opts.bookSheets = true;
if(program.sheetRows) opts.sheetRows = program.sheetRows;
-if(!program.formulae) opts.cellFormula = false;
if(program.password) opts.password = program.password;
+if(program.formulae) opts.cellFormula = true;
+else opts.cellFormula = false;
+
+if(program.all) {
+ opts.cellFormula = true;
+ opts.cellNF = true;
+}
if(program.dev) {
X.verbose = 2;
@@ -86,6 +94,8 @@ try {
process.exit(4);
}
+if(program.perf) return;
+
var oo = "";
if(!program.quiet) console.error(target_sheet);
if(program.formulae) oo = X.utils.get_formulae(ws).join("\n");
View
@@ -1 +1 @@
-XLS.version = '0.6.20';
+XLS.version = '0.6.21';
View
@@ -4,7 +4,7 @@ function new_buf(len) {
/* jshint +W056 */
}
function readIEEE754(buf, idx, isLE, nl, ml) {
- if(typeof isLE === 'undefined') isLE = true;
+ if(isLE === undefined) isLE = true;
if(!nl) nl = 8;
if(!ml && nl === 8) ml = 52;
var e, m, el = nl * 8 - ml - 1, eMax = (1 << el) - 1, eBias = eMax >> 1;
@@ -178,10 +178,12 @@ function CheckField(hexstr, fld) {
}
function prep_blob(blob, pos) {
- blob.read_shift = ReadShift.bind(blob);
- blob.chk = CheckField;
blob.l = pos || 0;
- var read = ReadShift.bind(blob), chk = CheckField.bind(blob);
- return [read, chk];
+ //var read = ReadShift.bind(blob), chk = CheckField.bind(blob);
+ //blob.read_shift = read;
+ //blob.chk = chk;
+ blob.read_shift = ReadShift;
+ blob.chk = CheckField;
+ //return [read, chk];
}
View
@@ -5,7 +5,7 @@ var _strrev = function(x) { return String(x).split("").reverse().join("");};
function fill(c,l) { return new Array(l+1).join(c); }
function pad(v,d,c){var t=String(v);return t.length>=d?t:(fill(c||0,d-t.length)+t);}
function rpad(v,d,c){var t=String(v);return t.length>=d?t:(t+fill(c||0,d-t.length));}
-SSF.version = '0.7.0';
+SSF.version = '0.7.1';
/* Options */
var opts_fmt = {
date1904:0,
@@ -252,7 +252,10 @@ var write_num = function(type, fmt, val) {
}
if(fmt.match(/^#+0+$/)) fmt = fmt.replace(/#/g,"");
if(fmt.match(/^00+$/)) return (val<0?"-":"")+pad(Math.round(aval),fmt.length);
- if(fmt.match(/^[#?]+$/)) return String(Math.round(val)).replace(/^0$/,"");
+ if(fmt.match(/^[#?]+$/)) {
+ o = String(Math.round(val)).replace(/^0$/,"");
+ return o.length > fmt.length ? o : fmt.substr(0,fmt.length-o.length).replace(/#/g,"").replace(/[?]/g," ") + o;
+ }
if((r = fmt.match(/^#*0*\.(0+)/))) {
o = Math.round(val * Math.pow(10,r[1].length));
rr = String(o/Math.pow(10,r[1].length)).replace(/^([^\.]+)$/,"$1."+r[1]).replace(/\.$/,"."+r[1]).replace(/\.([0-9]*)$/,function($$, $1) { return "." + $1 + fill("0", r[1].length-$1.length); });
@@ -278,20 +281,32 @@ var write_num = function(type, fmt, val) {
ff = write_num(type, "##########", val);
return "(" + ff.substr(0,3) + ") " + ff.substr(3, 3) + "-" + ff.substr(6);
}
- if((r = fmt.match(/^([?]+)([ ]?)\/([ ]?)([?]+)/))) {
- rr = Math.min(Math.max(r[1].length, r[4].length),7);
+ var oa = "";
+ if((r = fmt.match(/^([#0?]+)([ ]?)\/([ ]?)([#0?]+)/))) {
+ o="";
+ rr = Math.min(r[4].length,7);
ff = frac(aval, Math.pow(10,rr)-1, false);
- return sign + (ff[0]||(ff[1] ? "" : "0")) + (ff[1] ? pad(ff[1],rr," ") + r[2] + "/" + r[3] + rpad(ff[2],rr," "): fill(" ", 2*rr+1 + r[2].length + r[3].length));
+ o += sign;
+ oa = write_num("n", r[1], ff[1]);
+ if(oa[oa.length-1] == " ") oa = oa.substr(0,oa.length-1) + "0";
+ o += oa;
+ o += r[2];
+ o += "/";
+ o += r[3];
+ oa = rpad(ff[2],rr," ");
+ if(oa.length < r[4].length) oa = r[4].substr(r[4].length-oa.length).replace(/[?]/g," ").replace(/#/g,"") + oa;
+ o += oa;
+ return o;
}
- if((r = fmt.match(/^# ([?]+)([ ]?)\/([ ]?)([?]+)/))) {
+ if((r = fmt.match(/^# ([#0?]+)([ ]?)\/([ ]?)([#0?]+)/))) {
rr = Math.min(Math.max(r[1].length, r[4].length),7);
ff = frac(aval, Math.pow(10,rr)-1, true);
return sign + (ff[0]||(ff[1] ? "" : "0")) + " " + (ff[1] ? pad(ff[1],rr," ") + r[2] + "/" + r[3] + rpad(ff[2],rr," "): fill(" ", 2*rr+1 + r[2].length + r[3].length));
}
- if((r = fmt.match(/^[#0]+$/))) {
+ if((r = fmt.match(/^[#0?]+$/))) {
o = "" + Math.round(val);
if(fmt.length <= o.length) return o;
- return fmt.substr(0,fmt.length - o.length).replace(/#/g,"") + o;
+ return fmt.substr(0,fmt.length-o.length).replace(/#/g,"").replace(/\?/g," ") + o;
}
if((r = fmt.match(/^([#0]+)\.([#0]+)$/))) {
o = "" + val.toFixed(Math.min(r[2].length,10)).replace(/([^0])0+$/,"$1");
@@ -507,7 +522,9 @@ function eval_fmt(fmt, v, opts, flen) {
out[i].v = write_num(out[i].t, out[i].v, (flen >1 && v < 0 && i>0 && out[i-1].v == "-" ? -v:v));
out[i].t = 't';
}
- return out.map(function(x){return x.v;}).join("");
+ var retval = "";
+ for(i=0; i != out.length; ++i) if(out[i]) retval += out[i].v;
+ return retval;
}
SSF._eval = eval_fmt;
function choose_fmt(fmt, v, o) {
View
@@ -2,23 +2,20 @@
/* [MS-OLEDS] 2.1.3 FILETIME (Packet Version) */
/* [MS-OLEPS] 2.8 FILETIME (Packet Version) */
function parse_FILETIME(blob) {
- var read = ReadShift.bind(blob), chk = CheckField.bind(blob);
- var dwLowDateTime = read(4), dwHighDateTime = read(4);
+ var dwLowDateTime = blob.read_shift(4), dwHighDateTime = blob.read_shift(4);
return new Date(((dwHighDateTime/1e7*Math.pow(2,32) + dwLowDateTime/1e7) - 11644473600)*1000).toISOString().replace(/\.000/,"");
}
/* [MS-OSHARED] 2.3.3.1.4 Lpstr */
function parse_lpstr(blob, type, pad) {
- var read = ReadShift.bind(blob), chk = CheckField.bind(blob);
- var str = read('lpstr');
+ var str = blob.read_shift('lpstr');
if(pad) blob.l += (4 - ((str.length+1) % 4)) % 4;
return str;
}
/* [MS-OSHARED] 2.3.3.1.6 Lpwstr */
function parse_lpwstr(blob, type, pad) {
- var read = ReadShift.bind(blob), chk = CheckField.bind(blob);
- var str = read('lpwstr');
+ var str = blob.read_shift('lpwstr');
if(pad) blob.l += (4 - ((str.length+1) % 4)) % 4;
return str;
}
@@ -40,10 +37,9 @@ function parse_VtUnalignedString(blob, t) { if(!t) throw new Error("dafuq?"); re
/* [MS-OSHARED] 2.3.3.1.9 VtVecUnalignedLpstrValue */
function parse_VtVecUnalignedLpstrValue(blob) {
- var read = ReadShift.bind(blob), chk = CheckField.bind(blob);
- var length = read(4);
+ var length = blob.read_shift(4);
var ret = [];
- for(var i = 0; i != length; ++i) ret[i] = read('lpstr');
+ for(var i = 0; i != length; ++i) ret[i] = blob.read_shift('lpstr');
return ret;
}
@@ -75,7 +71,7 @@ function parse_VtVecHeadingPair(blob) {
/* [MS-OLEPS] 2.18.1 Dictionary (uses 2.17, 2.16) */
function parse_dictionary(blob,CodePage) {
- var read = ReadShift.bind(blob), chk = CheckField.bind(blob);
+ var read = ReadShift.bind(blob);
var cnt = read(4);
var dict = {};
for(var j = 0; j != cnt; ++j) {
@@ -118,7 +114,7 @@ function parse_VtVector(blob, cb) {
/* [MS-OLEPS] 2.15 TypedPropertyValue */
function parse_TypedPropertyValue(blob, type, _opts) {
- var read = ReadShift.bind(blob), chk = CheckField.bind(blob);
+ var read = ReadShift.bind(blob);
var t = read(2), ret, opts = _opts||{};
read(2);
if(type !== VT_VARIANT)
@@ -155,7 +151,7 @@ function parse_VTVectorVariant(blob) {
/* [MS-OLEPS] 2.20 PropertySet */
function parse_PropertySet(blob, PIDSI) {
var start_addr = blob.l;
- var read = ReadShift.bind(blob), chk = CheckField.bind(blob);
+ var read = ReadShift.bind(blob);
var size = read(4);
var NumProps = read(4);
var Props = [], i = 0;
View
@@ -144,13 +144,14 @@ function get_next_sector(idx) { return get_buffer_u32(idx); }
/** Chains */
var chkd = new Array(sectors.length), sector_list = [];
-var get_sector = function get_sector(k) { return sectors[k]; };
+var buf_chain = [];
for(i=0; i != sectors.length; ++i) {
var buf = [], k = (i + dir_start) % sectors.length;
+ buf_chain = [];
if(chkd[k]) continue;
- for(j=k; j<=MAXREGSECT; buf.push(j),j=get_next_sector(j)) chkd[j] = true;
+ for(j=k; j<=MAXREGSECT; buf.push(j),buf_chain.push(sectors[j]),j=get_next_sector(j)) chkd[j] = true;
sector_list[k] = {nodes: buf};
- sector_list[k].data = __toBuffer(Array(buf.map(get_sector)));
+ sector_list[k].data = __toBuffer(Array(buf_chain));
}
sector_list[dir_start].name = "!Directory";
if(nmfs > 0 && minifat_start !== ENDOFCHAIN) sector_list[minifat_start].name = "!MiniFAT";
View
@@ -21,7 +21,7 @@ function parslurp2(blob, length, cb) {
function parsebool(blob, length) { return blob.read_shift(length) === 0x1; }
-function parseuint16(blob, length) { return blob.read_shift(2, 'u'); }
+function parseuint16(blob) { return blob.read_shift(2, 'u'); }
function parseuint16a(blob, length) { return parslurp(blob,length,parseuint16);}
/* --- 2.5 Structures --- */
@@ -37,27 +37,25 @@ function parse_Bes(blob) {
/* [MS-XLS] 2.5.240 ShortXLUnicodeString */
function parse_ShortXLUnicodeString(blob) {
- var read = blob.read_shift.bind(blob);
- var cch = read(1);
- var fHighByte = read(1);
+ var cch = blob.read_shift(1);
+ var fHighByte = blob.read_shift(1);
var retval;
var width = 1 + (fHighByte === 0 ? 0 : 1), encoding = fHighByte ? 'dbcs' : 'sbcs';
- retval = cch ? read(encoding, cch) : "";
+ retval = cch ? blob.read_shift(encoding, cch) : "";
return retval;
}
/* 2.5.293 XLUnicodeRichExtendedString */
function parse_XLUnicodeRichExtendedString(blob) {
- var read_shift = blob.read_shift.bind(blob);
- var cch = read_shift(2), flags = read_shift(1);
+ var cch = blob.read_shift(2), flags = blob.read_shift(1);
var fHighByte = flags & 0x1, fExtSt = flags & 0x4, fRichSt = flags & 0x8;
var width = 1 + (flags & 0x1); // 0x0 -> utf8, 0x1 -> dbcs
var cRun, cbExtRst;
var z = {};
- if(fRichSt) cRun = read_shift(2);
- if(fExtSt) cbExtRst = read_shift(4);
+ if(fRichSt) cRun = blob.read_shift(2);
+ if(fExtSt) cbExtRst = blob.read_shift(4);
var encoding = (flags & 0x1) ? 'dbcs' : 'sbcs';
- var msg = cch === 0 ? "" : read_shift(encoding, cch);
+ var msg = cch === 0 ? "" : blob.read_shift(encoding, cch);
if(fRichSt) blob.l += 4 * cRun; //TODO: parse this
if(fExtSt) blob.l += cbExtRst; //TODO: parse this
z.t = msg;
@@ -67,8 +65,7 @@ function parse_XLUnicodeRichExtendedString(blob) {
/* 2.5.296 XLUnicodeStringNoCch */
function parse_XLUnicodeStringNoCch(blob, cch) {
- var read = blob.read_shift.bind(blob);
- var fHighByte = read(1);
+ var fHighByte = blob.read_shift(1);
var retval;
if(fHighByte===0) { retval = __utf8(blob,blob.l, blob.l+cch); blob.l += cch; }
else { retval = blob.read_shift('dbcs', cch); }
@@ -83,7 +80,7 @@ function parse_XLUnicodeString(blob) {
}
/* 2.5.342 Xnum */
-function parse_Xnum(blob, length) { return blob.read_shift('ieee754'); }
+function parse_Xnum(blob) { return blob.read_shift('ieee754'); }
/* 2.5.61 ControlInfo */
var parse_ControlInfo = parsenoop;
View
@@ -11,3 +11,4 @@ function evert(obj, arr) {
});
return o;
}
+
Oops, something went wrong.

0 comments on commit 9778152

Please sign in to comment.