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 <trev.norris@gmail.com>
This commit is contained in:
Jicheng Li authored and Trevor Norris committed 2014-09-25 12:17:11 -07:00
1 parent 51b6b6844e
commit f3473d7db6
1 file changed
+4 -1
+4 -1
View File
@@ -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