[Mono-dev] [PATCH] Fold a + 'b' + c to a + "b" + c in mcs
bmaurer at ximian.com
Tue Oct 11 03:12:44 EDT 2005
On Tue, 2005-10-11 at 03:06 -0400, Ben Maurer wrote:
> On Tue, 2005-10-11 at 07:59 +0100, Marek Safar wrote:
> > Hello Ben,
> > >Today I noticed a perf issue in corlib in a place where we did a + 'b' +
> > >c. The constant char in this case needs to be boxed and a string
> > >allocated for its value. A better way to write this is a + "b" + c,
> > >which saves two allocations.
> > >
> > >
> > Good idea, so why not extend this to all other constant cases like. "a"
> > + 1 + "c" etc.
> ToString there is culture dependent, for char it is not.
One thing we could do here, if you have:
string a, b;
string c = a + i + b;
We encode it as:
c = String.Concat (a, (object) i, b)
This requires boxing i. It would be better to say:
c = String.Concat (a, i.ToString (), b);
We avoid the boxing in this case. But it's 3 am now, maybe I'll make
that patch tomorrow :-).
More information about the Mono-devel-list