Permalink
Browse files

optimize part body

  • Loading branch information...
1 parent 9afc9fe commit 57731567ddf0aaa910f628a0f6923497dadd6120 @chjj chjj committed Oct 18, 2011
Showing with 13 additions and 1 deletion.
  1. +13 −1 lib/multipart.js
View
@@ -42,6 +42,11 @@ var Parser = function(type, options) {
this.key = new Buffer('\r\n--' + key);
+ this._key = {};
+ Array.prototype.forEach.call(this.key, function(ch) {
+ this._key[ch] = true;
+ }, this);
+
this.state = 'start';
this.pending = 0;
this.written = 0;
@@ -90,7 +95,8 @@ Parser.prototype._parse = function(data) {
, buff = this.buff
, key = this.key
, ch
- , val;
+ , val
+ , j;
for (; i < len; i++) {
if (this.pos >= 200) {
@@ -245,6 +251,12 @@ Parser.prototype._parse = function(data) {
len = data.length;
break;
default:
+ // boyer-moore-like algorithm
+ // at felixge's suggestion
+ while ((j = i + key.length - 1) < len) {
+ if (this._key[data[j]]) break;
+ i = j;
+ }
break;
}
break;

0 comments on commit 5773156

Please sign in to comment.