Re: string manipulation performance

2011-06-12 Thread Lloyd Dupont
Thanks Steven, that was very informative! "Steven Schveighoffer" wrote in message news:op.vwzrwdmteav7ka@localhost.localdomain... On Sun, 12 Jun 2011 21:02:05 -0400, Lloyd Dupont wrote: But... string being immutable I don't see the point of allocating some space for one.. Am I missing som

Re: string manipulation performance

2011-06-12 Thread Steven Schveighoffer
On Sun, 12 Jun 2011 21:02:05 -0400, Lloyd Dupont wrote: But... string being immutable I don't see the point of allocating some space for one.. Am I missing something? Reserving space for appending does not make that space immutable, yet. As far as the runtime is concerned, that space is

Re: string manipulation performance

2011-06-12 Thread Jonathan M Davis
On 2011-06-12 18:02, Lloyd Dupont wrote: > But... string being immutable I don't see the point of allocating some > space for one.. > Am I missing something? Just because it's immutable doesn't mean that it doesn't need to exist at runtime. All immutable means is that you can't change it. It coul

Re: string manipulation performance

2011-06-12 Thread Lloyd Dupont
Thanks! "Jonathan M Davis" wrote in message news:mailman.851.1307909610.14074.digitalmars-d- Also, std.string.repeat has been scheduled for deprecation. You should use std.array.replicate instead. It does the same thing but for all arrays instead of just strings. - Jonathan M Davis

Re: string manipulation performance

2011-06-12 Thread Lloyd Dupont
But... string being immutable I don't see the point of allocating some space for one.. Am I missing something? "Steven Schveighoffer" wrote in message news:op.vwy503w4eav7ka@localhost.localdomain... On Sun, 12 Jun 2011 12:49:25 -0400, Lloyd Dupont wrote: I have a method like that: === pub

Re: string manipulation performance

2011-06-12 Thread Jonathan M Davis
On 2011-06-12 11:08, Steven Schveighoffer wrote: > On Sun, 12 Jun 2011 12:49:25 -0400, Lloyd Dupont > > wrote: > > I have a method like that: > > === > > public string repeat(string s, int num) > > { > > > > string result = s; > > for (int i=1; i > > > result ~= s; > >

Re: string manipulation performance

2011-06-12 Thread Steven Schveighoffer
On Sun, 12 Jun 2011 12:49:25 -0400, Lloyd Dupont wrote: I have a method like that: === public string repeat(string s, int num) { string result = s; for (int i=1; i The runtime tries its best to avoid allocating a new string on each append. Please read the manual on appending, and

string manipulation performance

2011-06-12 Thread Lloyd Dupont
I have a method like that: === public string repeat(string s, int num) { string result = s; for (int i=1; i