Thread overview | |||||
---|---|---|---|---|---|
|
April 19, 2005 Triple, quadruple concatenation? | ||||
---|---|---|---|---|
| ||||
I guess this is a feature request. Say you've got: char[] a, b, c, d; I think that this: a = b ~ c ~ d; ..should cancatenate in one step, kinda like this: a.length = b.length + c.length + d.length; a[0 .. b.length] = b; a[b.length .. c.length] = c; a[b.length + c.length .. d.length] = d; ..instead of working like this: a = (b ~ c) ~ d; It would be faster because it involves less copying and allocation, right? Does the D language spec allow concatenation to be implemented that way? or does it require something like a strict left to right order of operations, one concatenation operator at a time? How do dmd and gdc do it? -Sterling |
April 19, 2005 Re: Triple, quadruple concatenation? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sterling Christensen | On Tue, 19 Apr 2005 23:32:44 +0000 (UTC), Sterling Christensen wrote: > I guess this is a feature request. > > Say you've got: > char[] a, b, c, d; > > I think that this: > a = b ~ c ~ d; > > ..should cancatenate in one step, kinda like this: > a.length = b.length + c.length + d.length; > a[0 .. b.length] = b; > a[b.length .. c.length] = c; > a[b.length + c.length .. d.length] = d; > > ..instead of working like this: > a = (b ~ c) ~ d; > > It would be faster because it involves less copying and allocation, right? > > Does the D language spec allow concatenation to be implemented that way? or does it require something like a strict left to right order of operations, one concatenation operator at a time? How do dmd and gdc do it? > I don't know with respect to D, but the Euphoria language recently made this optimization and it did shave off a lot wasted time. A common idiom is inserting an item ... A = A[0 .. x] ~ newitem ~ A[x .. $]; which greatly benefits from this optimization. -- Derek Melbourne, Australia 20/04/2005 9:44:52 AM |
April 20, 2005 Re: Triple, quadruple concatenation? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sterling Christensen | I an into trouble trying to do things like that and wasn't even sure why. Should work... would be more intuitive. TZ "Sterling Christensen" <Sterling_member@pathlink.com> wrote in message news:d444es$1qob$1@digitaldaemon.com... > I guess this is a feature request. > > Say you've got: > char[] a, b, c, d; > > I think that this: > a = b ~ c ~ d; > > ..should cancatenate in one step, kinda like this: > a.length = b.length + c.length + d.length; > a[0 .. b.length] = b; > a[b.length .. c.length] = c; > a[b.length + c.length .. d.length] = d; > > ..instead of working like this: > a = (b ~ c) ~ d; > > It would be faster because it involves less copying and allocation, right? > > Does the D language spec allow concatenation to be implemented that way? or does it require something like a strict left to right order of operations, one concatenation operator at a time? How do dmd and gdc do it? > > -Sterling |
Copyright © 1999-2021 by the D Language Foundation