On Thu, Sep 11, 2008 at 11:49 AM, Aaron Boodman <[EMAIL PROTECTED]> wrote:
> On Thu, Sep 11, 2008 at 11:44 AM, Chris Prince <[EMAIL PROTECTED]> wrote:
>> For example, most methods that today take a String could instead
>> accept a StringOrBlob. Both objects represent a chunk of immutable
>> data; it just happens to be text- or binary-based data.
>>
>> Instead of 'StringBuilder' or 'ArrayBuilder' classes, there are
>> methods like concat(). Couldn't we add Blob.concat(), and let it
>> accept a String or Blob?
>
> Many languages and frameworks that have immutable strings also have
> StringBuilders. Off the top of my head, I know that Java and .Net both
> have this. There are probably others. JavaScript doesn't, but I don't
> think that by itself should rule it out.
Also note that the typical JS pattern is to use an Array as a
StringBuilder. So that's probably where there is no official separate
StringBuilder class.
var stringBuilder = [];
for (var i = 0; i < 100; i++) { stringBuilder.push(String(i)); }
var string = stringBuilder.join("");
String.concat() is well known to be very inefficient and js devs are
usually recommended to use the above pattern instead when
concatenating large amounts of strings (though modern engines have
hyper optimizied the += operator for strings, so it has become a
little less of an issue).
I wonder if there'd be similar problems with Blob.concat().
- a