From 0f990781f14a3410055a1abd6aebb46dcdc87bb5 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Tue, 16 Dec 2008 23:43:50 +0000 Subject: [PATCH] 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. --- translators/BibTeX.js | 47 ++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/translators/BibTeX.js b/translators/BibTeX.js index 008faff997..8e456c91d9 100644 --- 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