Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Remove complex string appending in http's send() method.
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed May 29, 2009
1 parent 247c9d2 commit aceb198
Showing 1 changed file with 0 additions and 33 deletions.
33 changes: 0 additions & 33 deletions src/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,45 +102,12 @@ function toRaw(string) {
return a;
}

// The send method appends data onto the output array. The deal is,
// the data is either an array of integer, representing binary or it
// is a string in which case it's UTF8 encoded.
// Two things to be considered:
// - we should be able to send mixed encodings.
// - we don't want to call connection.send("smallstring") because that
// is wasteful. *I think* its rather faster to concat inside of JS
// Thus I attempt to concat as much as possible.
//
// XXX this function is extremely ugly
function send (output, data, encoding) {
if (data.constructor === String)
encoding = encoding || "ascii";
else
encoding = "raw";

if (output.length == 0) {
output.push([data, encoding]);
return;
}

var li = output.length-1;
var last_encoding = output[li][1];

if (data.constructor === String) {
if ( last_encoding === encoding
|| (last_encoding === "utf8" && encoding === "ascii")
)
{
output[li][0] += data;
return;
}
}

if (data.constructor === Array && last_encoding === encoding) {
output[li][0] = output[li][0].concat(data);
return;
}

output.push([data, encoding]);
};

Expand Down

0 comments on commit aceb198

Please sign in to comment.