In this specific case you could use Stdio.Buffer instead.

Change writeme to be a buffer, then add to it using ->add(string)

In the socket_write function, you only need this:

if( sizeof( con->_writeme ) )
  con->_writeme->output_to(con->_socket);

This should be O(1) regardless of the buffer size, and in general
slightly faster than strings even for short:ish buffers.

On Wed, Aug 19, 2015 at 2:39 AM, Chris Angelico <ros...@gmail.com> wrote:
> On Wed, Aug 19, 2015 at 6:13 AM, Per Hedbor () @ Pike (-) developers
> forum <10...@lyskom.lysator.liu.se> wrote:
>> Another advantage with this method is that it is reasonably trivial to
>> add new string types. As an example that I am seriously considering: A
>> string that is a tail port of another string.
>>
>> The tail-string would be used for this somewhat unfortunate but rather
>> common coding pattern:
>>
>> sscanf( str, "%2c%s", part, str );
>>
>> and, in a similar manner:
>>
>> len = file->write(str);
>> str = str[written..]
>>
>> These are both O(n^2), but if tail-of string are added they could both
>> be about O(n), only reallocate the data if more than 50% is wasted.
>
> This specific improvement would be useful to this code, although I'm
> noticing the slowdown only when I do stupid stuff for benchmarking.
>
> https://github.com/Rosuav/Hogan/blob/master/hogan.pike#L25
>
> Figuring out a good chunk size in application code is hard. If I could
> simply code idiomatically without chunking, and let the language worry
> about efficiency, it'd be awesome.
>
> ChrisA
  • spl... Per Hedbor () @ Pike (-) developers forum
    • ... Marcus Comstedt (ACROSS) (Hail Ilpalazzo!) @ Pike (-) developers forum
      • ... Per Hedbor () @ Pike (-) developers forum
        • ... Marcus Comstedt (ACROSS) (Hail Ilpalazzo!) @ Pike (-) developers forum
    • ... Chris Angelico
      • ... Per Hedbor
        • ... Chris Angelico
          • ... Per Hedbor
            • ... Chris Angelico

Reply via email to