From ecee362e006a97e90553cb7d705c2ed1814ea39a Mon Sep 17 00:00:00 2001 From: SheetJS Date: Sat, 22 Feb 2014 16:36:28 -0500 Subject: [PATCH] version bump 0.5.10-a: xlsx performance - utf8 translation pushes to array rather than string concat - large_strings test actually runs now (rather than blowing up) --- Makefile | 2 +- bits/31_version.js | 2 +- bits/36_xlsxutils.js | 10 +++++----- bits/37_xlsbutils.js | 8 ++++---- bits/72_wsxml.js | 5 +---- bits/90_utils.js | 8 ++++---- package.json | 2 +- test.js | 6 ++++++ tests.lst | 4 ++-- tests/files | 2 +- xlsx.js | 33 +++++++++++++++------------------ 11 files changed, 41 insertions(+), 41 deletions(-) diff --git a/Makefile b/Makefile index 4b1c5b0..5a9322c 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ $(TARGET): $(DEPS) cat $^ > $@ bits/31_version.js: package.json - echo "XLSX.version = '"`grep version package.json | awk '{gsub(/[^0-9\.]/,"",$$2); print $$2}'`"';" > $@ + echo "XLSX.version = '"`grep version package.json | awk '{gsub(/[^0-9a-z\.-]/,"",$$2); print $$2}'`"';" > $@ .PHONY: clean clean: diff --git a/bits/31_version.js b/bits/31_version.js index bf66ead..9889ba5 100644 --- a/bits/31_version.js +++ b/bits/31_version.js @@ -1 +1 @@ -XLSX.version = '0.5.10'; +XLSX.version = '0.5.10-a'; diff --git a/bits/36_xlsxutils.js b/bits/36_xlsxutils.js index ce6aba4..6e07f85 100644 --- a/bits/36_xlsxutils.js +++ b/bits/36_xlsxutils.js @@ -47,20 +47,20 @@ function parsexmlbool(value, tag) { } var utf8read = function(orig) { - var out = "", i = 0, c = 0, c1 = 0, c2 = 0, c3 = 0; + var out = [], i = 0, c = 0, c1 = 0, c2 = 0, c3 = 0; while (i < orig.length) { c = orig.charCodeAt(i++); - if (c < 128) out += _chr(c); + if (c < 128) out.push(_chr(c)); else { c2 = orig.charCodeAt(i++); - if (c>191 && c<224) out += _chr((c & 31) << 6 | c2 & 63); + if (c>191 && c<224) out.push(_chr((c & 31) << 6 | c2 & 63)); else { c3 = orig.charCodeAt(i++); - out += _chr((c & 15) << 12 | (c2 & 63) << 6 | c3 & 63); + out.push(_chr((c & 15) << 12 | (c2 & 63) << 6 | c3 & 63)); } } } - return out; + return out.join(""); }; // matches ... extracts content diff --git a/bits/37_xlsbutils.js b/bits/37_xlsbutils.js index 0dd302c..bf98a7a 100644 --- a/bits/37_xlsbutils.js +++ b/bits/37_xlsbutils.js @@ -37,7 +37,7 @@ var __readDoubleLE = function(b, idx) { return b.readDoubleLE ? b.readDoubleLE(i function ReadShift(size, t) { - var o, w, vv, i, loc; t = t || 'u'; + var o = "", oo = [], w, vv, i, loc; t = t || 'u'; if(size === 'ieee754') { size = 8; t = 'f'; } switch(size) { case 1: o = __readUInt8(this, this.l); break; @@ -49,11 +49,11 @@ function ReadShift(size, t) { /* sbcs and dbcs support continue records in the SST way TODO codepages */ /* TODO: DBCS http://msdn.microsoft.com/en-us/library/cc194788.aspx */ - case 'dbcs': size = 2*t; o = ""; loc = this.l; + case 'dbcs': size = 2*t; loc = this.l; for(i = 0; i != t; ++i) { - o += _getchar(__readUInt16LE(this, loc)); + oo.push(_getchar(__readUInt16LE(this, loc))); loc+=2; - } break; + } o = oo.join(""); break; case 'sbcs': size = t; o = ""; loc = this.l; for(i = 0; i != t; ++i) { diff --git a/bits/72_wsxml.js b/bits/72_wsxml.js index e0c57a1..0e35fac 100644 --- a/bits/72_wsxml.js +++ b/bits/72_wsxml.js @@ -26,10 +26,7 @@ function parse_ws_xml(data, opts) { cells.forEach(function(c, idx) { if(c === "" || c.trim() === "") return; var cref = c.match(/r=["']([^"']*)["']/); c = "]*>/)||[c])[0]); delete cell[0]; var d = c.substr(c.indexOf('>')+1); var p = {}; diff --git a/bits/90_utils.js b/bits/90_utils.js index ce166e1..5a8cb29 100644 --- a/bits/90_utils.js +++ b/bits/90_utils.js @@ -63,9 +63,9 @@ function sheet_to_csv(sheet, opts) { default: throw 'unrecognized type ' + val.t; } }; - var out = "", txt = ""; + var out = [], txt = ""; opts = opts || {}; - if(!sheet || !sheet["!ref"]) return out; + if(!sheet || !sheet["!ref"]) return ""; var r = XLSX.utils.decode_range(sheet["!ref"]); var fs = opts.FS||",", rs = opts.RS||"\n"; @@ -79,9 +79,9 @@ function sheet_to_csv(sheet, opts) { txt = "\"" + txt.replace(/"/g, '""') + "\""; row.push(txt); } - out += row.join(fs) + (rs); + out.push(row.join(fs)); } - return out; + return out.join(rs) + (out.length ? rs : ""); } var make_csv = sheet_to_csv; diff --git a/package.json b/package.json index 5c6338e..68c611c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xlsx", - "version": "0.5.10", + "version": "0.5.10-a", "author": "sheetjs", "description": "XLSB / XLSX / XLSM parser", "keywords": [ "xlsx", "xlsb", "xlsm", "office", "excel", "spreadsheet" ], diff --git a/test.js b/test.js index 5be532b..4635145 100644 --- a/test.js +++ b/test.js @@ -55,6 +55,12 @@ function parsetest(x, wb) { describe(x + ' should generate correct output', function() { wb.SheetNames.forEach(function(ws, i) { var name = (dir + x + '.' + i + '.csv'); + if(x.substr(-5) === ".xlsb") { + root = x.slice(0,-5); + //if(!fs.existsSync(name)) name=(dir + root + '.xlsx.'+i+'.csv'); + //if(!fs.existsSync(name)) name=(dir + root + '.xlsm.'+i+'.csv'); + //if(!fs.existsSync(name)) name=(dir + root + '.xls.'+i+'.csv'); + } it('#' + i + ' (' + ws + ')', fs.existsSync(name) ? function() { var file = fs.readFileSync(name, 'utf-8'); var csv = XLSX.utils.make_csv(wb.Sheets[ws]); diff --git a/tests.lst b/tests.lst index 86a9eaf..c6ef873 100644 --- a/tests.lst +++ b/tests.lst @@ -2,7 +2,7 @@ RkNumber.xlsb comments_stress_test.xlsb custom_properties.xlsb formula_stress_test.xlsb -large_strings.xlsb.pending +large_strings.xlsb merge_cells.xlsb named_ranges_2011.xlsb number_format.xlsb @@ -162,7 +162,7 @@ jxls-core_simple.xlsx jxls-examples_stress1.xlsx jxls-examples_stress2.xlsx jxls-reader_departmentData.xlsx -large_strings.xlsx.pending +large_strings.xlsx merge_cells.xlsx mixed_sheets.xlsx named_ranges_2011.xlsx diff --git a/tests/files b/tests/files index 15d10e8..aad3f9c 160000 --- a/tests/files +++ b/tests/files @@ -1 +1 @@ -Subproject commit 15d10e8eba67bafd07a406b3345c9309739b5da1 +Subproject commit aad3f9c021d2b70fd4c288e001085b168eba6baf diff --git a/xlsx.js b/xlsx.js index b3c6fac..0b4785a 100644 --- a/xlsx.js +++ b/xlsx.js @@ -423,7 +423,7 @@ SSF.load_table = function(tbl) { for(var i=0; i!=0x0188; ++i) if(tbl[i]) SSF.loa make_ssf(SSF); var XLSX = {}; (function(XLSX){ -XLSX.version = '0.5.10'; +XLSX.version = '0.5.10-a'; var current_codepage, current_cptable, cptable; if(typeof module !== "undefined" && typeof require !== 'undefined') { if(typeof cptable === 'undefined') cptable = require('codepage'); @@ -518,20 +518,20 @@ function parsexmlbool(value, tag) { } var utf8read = function(orig) { - var out = "", i = 0, c = 0, c1 = 0, c2 = 0, c3 = 0; + var out = [], i = 0, c = 0, c1 = 0, c2 = 0, c3 = 0; while (i < orig.length) { c = orig.charCodeAt(i++); - if (c < 128) out += _chr(c); + if (c < 128) out.push(_chr(c)); else { c2 = orig.charCodeAt(i++); - if (c>191 && c<224) out += _chr((c & 31) << 6 | c2 & 63); + if (c>191 && c<224) out.push(_chr((c & 31) << 6 | c2 & 63)); else { c3 = orig.charCodeAt(i++); - out += _chr((c & 15) << 12 | (c2 & 63) << 6 | c3 & 63); + out.push(_chr((c & 15) << 12 | (c2 & 63) << 6 | c3 & 63)); } } } - return out; + return out.join(""); }; // matches ... extracts content @@ -590,7 +590,7 @@ var __readDoubleLE = function(b, idx) { return b.readDoubleLE ? b.readDoubleLE(i function ReadShift(size, t) { - var o, w, vv, i, loc; t = t || 'u'; + var o = "", oo = [], w, vv, i, loc; t = t || 'u'; if(size === 'ieee754') { size = 8; t = 'f'; } switch(size) { case 1: o = __readUInt8(this, this.l); break; @@ -602,11 +602,11 @@ function ReadShift(size, t) { /* sbcs and dbcs support continue records in the SST way TODO codepages */ /* TODO: DBCS http://msdn.microsoft.com/en-us/library/cc194788.aspx */ - case 'dbcs': size = 2*t; o = ""; loc = this.l; + case 'dbcs': size = 2*t; loc = this.l; for(i = 0; i != t; ++i) { - o += _getchar(__readUInt16LE(this, loc)); + oo.push(_getchar(__readUInt16LE(this, loc))); loc+=2; - } break; + } o = oo.join(""); break; case 'sbcs': size = t; o = ""; loc = this.l; for(i = 0; i != t; ++i) { @@ -1332,10 +1332,7 @@ function parse_ws_xml(data, opts) { cells.forEach(function(c, idx) { if(c === "" || c.trim() === "") return; var cref = c.match(/r=["']([^"']*)["']/); c = "]*>/)||[c])[0]); delete cell[0]; var d = c.substr(c.indexOf('>')+1); var p = {}; @@ -2935,9 +2932,9 @@ function sheet_to_csv(sheet, opts) { default: throw 'unrecognized type ' + val.t; } }; - var out = "", txt = ""; + var out = [], txt = ""; opts = opts || {}; - if(!sheet || !sheet["!ref"]) return out; + if(!sheet || !sheet["!ref"]) return ""; var r = XLSX.utils.decode_range(sheet["!ref"]); var fs = opts.FS||",", rs = opts.RS||"\n"; @@ -2951,9 +2948,9 @@ function sheet_to_csv(sheet, opts) { txt = "\"" + txt.replace(/"/g, '""') + "\""; row.push(txt); } - out += row.join(fs) + (rs); + out.push(row.join(fs)); } - return out; + return out.join(rs) + (out.length ? rs : ""); } var make_csv = sheet_to_csv;