Skip to content

Commit

Permalink
Performance work on string joins.
Browse files Browse the repository at this point in the history
Reviewed by @tolmasky.
  • Loading branch information
tolmasky committed Dec 27, 2012
1 parent 5701c6d commit 44e8a39
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions languages/Objective-J/lib/Compiler.js
Expand Up @@ -34,25 +34,18 @@ module.exports.compile = function(source)

// "Hand splicing" is much faster than calling splice each time...
var index = 0;
count = splices.length,
characters = source.split("");
var count = splices.length;
var result = "";
var cursor = 0;

for (; index < count; ++index)
{
var splice = splices[index],
start = splice[0],
stop = start + splice[1];

for (; start < stop; ++start)
characters[start] = "";

if (stop - 1 < 0)
characters[0] = splice[2] + characters[0];
else
characters[stop - 1] += splice[2];
var splice = splices[index];
result += source.substring(cursor, splice[0]) + splice[2];
cursor = splice[0] + splice[1];
}

var result = characters.join("");
result += source.substr(cursor);

return result;
}
Expand Down

0 comments on commit 44e8a39

Please sign in to comment.