toString refactor in druntime

H. S. Teoh via Digitalmars-d digitalmars-d at puremagic.com
Fri Oct 31 15:21:15 PDT 2014


On Fri, Oct 31, 2014 at 02:57:58PM -0700, Andrei Alexandrescu via Digitalmars-d wrote:
> On 10/31/14 2:11 PM, H. S. Teoh via Digitalmars-d wrote:
> >On Fri, Oct 31, 2014 at 02:01:50PM -0700, Walter Bright via Digitalmars-d wrote:
> >>On 10/31/2014 12:07 PM, H. S. Teoh via Digitalmars-d wrote:
> >>>On Fri, Oct 31, 2014 at 12:04:24PM -0700, Walter Bright via Digitalmars-d wrote:
> >>>>On 10/27/2014 12:42 AM, Benjamin Thaut wrote:
> >>>>>I'm planning on doing a pull request for druntime which rewrites
> >>>>>every toString function within druntime to use the new sink
> >>>>>signature. That way druntime would cause a lot less allocations
> >>>>>which end up beeing garbage right away. Are there any objections
> >>>>>against doing so? Any reasons why such a pull request would not
> >>>>>get accepted?
> >>>>
> >>>>Why a sink version instead of an Output Range?
> >>>
> >>>To allow toString to be a virtual function, perhaps?
> >>
> >>Output ranges can be virtual functions. All an output range is is a
> >>type with a "put" method.
> >
> >The problem is that you don't know the type of the output range in
> >advance. So you'd have to templatize toString. Which means it can no
> >longer be virtual.
> 
> Yah, for such stuff a delegate that takes a const(char)[] comes to
> mind. --
[...]

Which is what the sink version of toString currently does.


T

-- 
Error: Keyboard not attached. Press F1 to continue. -- Yoon Ha Lee, CONLANG


More information about the Digitalmars-d mailing list