Parser: don't delay buffer clearing

fork
mscdex 11 years ago
parent 625494fc47
commit 75e7b921e0

@ -105,16 +105,14 @@ Parser.prototype._parse = function(data) {
this.debug && this.debug('<= ' + inspect(this._buffer)); this.debug && this.debug('<= ' + inspect(this._buffer));
var clearBuffer = false;
if (RE_PRECEDING.test(this._buffer)) { if (RE_PRECEDING.test(this._buffer)) {
var firstChar = this._buffer[0]; var firstChar = this._buffer[0];
if (firstChar === '*') if (firstChar === '*')
clearBuffer = this._resUntagged(); this._resUntagged();
else if (firstChar === 'A') else if (firstChar === 'A')
clearBuffer = this._resTagged(); this._resTagged();
else if (firstChar === '+') else if (firstChar === '+')
clearBuffer = this._resContinue(); this._resContinue();
if (this._literallen > 0 && i < datalen) { if (this._literallen > 0 && i < datalen) {
// literal data included in this chunk -- put it back onto stream // literal data included in this chunk -- put it back onto stream
@ -126,12 +124,9 @@ Parser.prototype._parse = function(data) {
} }
} }
} else { } else {
this._buffer = '';
this.emit('other', this._buffer); this.emit('other', this._buffer);
clearBuffer = true;
} }
if (clearBuffer)
this._buffer = '';
} }
} }
@ -140,7 +135,6 @@ Parser.prototype._parse = function(data) {
}; };
Parser.prototype._resTagged = function() { Parser.prototype._resTagged = function() {
var ret = false;
if (m = RE_LITERAL.exec(this._buffer)) { if (m = RE_LITERAL.exec(this._buffer)) {
// non-BODY literal -- buffer it // non-BODY literal -- buffer it
this._buffer = this._buffer.replace(RE_LITERAL, LITPLACEHOLDER); this._buffer = this._buffer.replace(RE_LITERAL, LITPLACEHOLDER);
@ -152,6 +146,7 @@ Parser.prototype._resTagged = function() {
type = m[2].toLowerCase(), type = m[2].toLowerCase(),
textCode = (m[3] ? parseTextCode(m[3], this._literals) : m[3]), textCode = (m[3] ? parseTextCode(m[3], this._literals) : m[3]),
text = m[4]; text = m[4];
this._buffer = '';
this._literals = []; this._literals = [];
@ -161,15 +156,11 @@ Parser.prototype._resTagged = function() {
textCode: textCode, textCode: textCode,
text: text text: text
}); });
ret = true;
} }
return ret;
}; };
Parser.prototype._resUntagged = function() { Parser.prototype._resUntagged = function() {
var ret = false, self = this, m; var self = this, m;
if (m = RE_BODYLITERAL.exec(this._buffer)) { if (m = RE_BODYLITERAL.exec(this._buffer)) {
// BODY literal -- stream it // BODY literal -- stream it
var which = m[1], size = parseInt(m[2], 10); var which = m[1], size = parseInt(m[2], 10);
@ -191,6 +182,7 @@ Parser.prototype._resUntagged = function() {
this._literallen = parseInt(m[1], 10); this._literallen = parseInt(m[1], 10);
this._tryread(this._literallen); this._tryread(this._literallen);
} else if (m = RE_UNTAGGED.exec(this._buffer)) { } else if (m = RE_UNTAGGED.exec(this._buffer)) {
this._buffer = '';
// normal single line response // normal single line response
// m[1] or m[3] = response type // m[1] or m[3] = response type
@ -250,14 +242,15 @@ Parser.prototype._resUntagged = function() {
textCode: textCode, textCode: textCode,
text: val text: val
}); });
ret = true;
} else } else
ret = true; this._buffer = '';
return ret;
}; };
Parser.prototype._resContinue = function() { Parser.prototype._resContinue = function() {
var m = RE_CONTINUE.exec(this._buffer), textCode, text = m[2]; var m = RE_CONTINUE.exec(this._buffer),
textCode,
text = m[2];
this._buffer = '';
if (m[1] !== undefined) if (m[1] !== undefined)
textCode = parseTextCode(m[1], this._literals); textCode = parseTextCode(m[1], this._literals);
@ -266,8 +259,6 @@ Parser.prototype._resContinue = function() {
textCode: textCode, textCode: textCode,
text: text text: text
}); });
return true;
}; };
function indexOfCh(buffer, len, i, ch) { function indexOfCh(buffer, len, i, ch) {

Loading…
Cancel
Save