www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 0f990781f14a3410055a1abd6aebb46dcdc87bb5
parent b5f3448304a3db9ccb17fce43d67fad740cd0f2b
Author: Dan Stillman <dstillman@zotero.org>
Date:   Tue, 16 Dec 2008 23:43:50 +0000

Fixes #1219, Increase BibTeX read buffer and read only initial 1MB

A 1.5MB RIS file now goes through BibTeX detection in about 3 seconds instead of...longer. I'm not sure the limit really needs to be 1MB, either.


Diffstat:
Mtranslators/BibTeX.js | 45++++++++++++++++++++++++++++++---------------
1 file changed, 30 insertions(+), 15 deletions(-)

diff --git a/translators/BibTeX.js b/translators/BibTeX.js @@ -8,32 +8,47 @@ "maxVersion":"", "priority":200, "inRepository":true, - "lastUpdated":"2008-11-23 21:30:00" + "lastUpdated":"2008-12-16 23:13:33" } Zotero.configure("dataMode", "block"); Zotero.addOption("exportCharset", "UTF-8"); function detectImport() { + var maxChars = 1048576; // 1MB + + var inComment = false; var block = ""; - var read; + var buffer = ""; + var chr = ""; + var charsRead = 0; var re = /^\s*@[a-zA-Z]+[\(\{]/; - var lines_read = 0; - while(read = Zotero.read(1)) { - if(read == "%") { - // read until next newline - block = ""; - while((read = Zotero.read(1)) && read != "\r" && read != "\n") {} - } else if((read == "\n" || read == "\r") && block) { - // check if this is a BibTeX entry - if(re.test(block)) { - return true; + while((buffer = Zotero.read(4096)) && charsRead < maxChars) { + Zotero.debug("Scanning " + buffer.length + " characters for BibTeX"); + charsRead += buffer.length; + for (var i=0; i<buffer.length; i++) { + chr = buffer[i]; + + if (inComment && chr != "\r" && chr != "\n") { + continue; } + inComment = false; - block = ""; - } else if(" \n\r\t".indexOf(read) == -1) { - block += read; + if(chr == "%") { + // read until next newline + block = ""; + inComment = true; + } else if((chr == "\n" || chr == "\r") && block) { + // check if this is a BibTeX entry + if(re.test(block)) { + return true; + } + + block = ""; + } else if(" \n\r\t".indexOf(chr) == -1) { + block += chr; + } } } }