From f3473d7db696f78b284c7a874ba33ec5e2b91309 Mon Sep 17 00:00:00 2001 From: Jicheng Li Date: Sun, 14 Sep 2014 23:40:49 +0800 Subject: [PATCH] readline: fix performance issue when large line Only run lineEnding.test() on the newly acquired chunk of string instead of on the entire line buffer. Reviewed-by: Trevor Norris --- lib/readline.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/readline.js b/lib/readline.js index add3a6a4bd9..a3f1b9d5801 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -310,11 +310,14 @@ Interface.prototype._normalWrite = function(b) { this._sawReturn = false; } + // Run test() on the new string chunk, not on the entire line buffer. + var newPartContainsEnding = lineEnding.test(string); + if (this._line_buffer) { string = this._line_buffer + string; this._line_buffer = null; } - if (lineEnding.test(string)) { + if (newPartContainsEnding) { this._sawReturn = /\r$/.test(string); // got one or more newlines; process into "line" events