Branch: Tag:

2014-09-12

2014-09-12 11:42:43 by Per Hedbor <ph@opera.com>

When we know the types we can optimize pop and friends. Use that.

312:    *! doing so could result in an infinite loop (since no data is    *! added, the range_error will be called again immediately).    */ -  PIKEFUN int(0..1) range_error( int howmuch ) +  PIKEFUN int(0..1) range_error( int range )    flags ID_PROTECTED;    { -  /* Default: throw error if so desired, otherwise return 0. */ -  pop_n_elems(args); -  push_int(0); +  Pike_sp[-1].u.integer = 0;    }       static void io_range_error_throw( IOBuffer *io, int howmuch )
989:       PIKEFUN int(0..) _size_object( )    { -  RETURN THIS->malloced ? THIS->allocated : 0; +  RETURN THIS->malloced ? THIS->allocated : THIS->stash.len;    }       /*! @decl IOBuffer add( AddArgument ... data )
1257:    flags ID_PROTECTED;    {    IOBuffer *io = THIS; -  pop_stack(); +     if( off < 0 )    off = io_len(io)-off;       if( io_avail( io, off ) ) -  push_int( io_read_pointer(io)[off] ); +  Pike_sp[-1].u.integer = io_read_pointer(io)[off];    else -  push_int(-1); +  Pike_sp[-1].u.integer = -1;    }       /*! @decl protected int `[]=(int off, int char)
1275:    flags ID_PROTECTED;    {    IOBuffer *io = THIS; +     io_ensure_malloced( io, 0 );       if( off < 0 ) off = io_len(io)-off; -  +  again:    if( io_avail( io, off ) )    {    io_read_pointer(io)[off]=(val&0xff);    }    else    { -  /* hm, well. We could extend the buffer? */ -  push_int(-1); +  /* hm, well. We could extend the buffer. Should we? */ +  if( io_range_error(io, off ) ) +  goto again; +  Pike_error("Writing outside buffer\n");    }    }   
1377:    if( TYPEOF(*m) == PIKE_T_INT )    io_set_error_mode( THIS, m->u.integer ? buffer_error_program : 0 );    else -  { +     io_set_error_mode( THIS, program_from_svalue(m)); -  } +     pop_stack();    ref_push_object(Pike_fp->current_object);    }
1396:    push_object( io_read_buffer( THIS, 0, 0 ) );    }    -  PIKEFUN string(0..255) _sprintf(int o, mapping ignore) +  PIKEFUN string(0..255) _sprintf(int o, mapping UNUSED)    flags ID_PROTECTED;    { -  pop_n_elems(args); -  if( o == 'O' ) +  pop_n_elems(args-1); +  Pike_sp--; +  switch( o )    { -  +  case 'O': +  {    push_text("%O(%d bytes, read=[..%d] data=[%d..%d] free=[%d..%d] %s%s)");    ref_push_program(Pike_fp->current_object->prog);    /* io_len [..offset] [offset..len] [..allocated] */
1419:    push_text("");    f_sprintf(10);    } -  else +  break; +  +  case 's': +  push_string( io_read_string( THIS, io_len(THIS)) ); +  break; +  +  case 'q': +  push_text("%q"); +  push_string( io_read_string( THIS, io_len(THIS)) ); +  f_sprintf(2); +  break; +  default:    push_undefined();    } -  +  }       /*! @decl string(8bit) read_hstring( int(0..) n )    *!
1448:    if (len < 0) {    /* io_avail() in io_read_number() failed. */    CALL_AND_UNSET_ONERROR(e); -  push_int(0); +  Pike_sp[-1].u.integer = 0;    return;    }   
1457:       if( s ) {    io_unset_rewind_on_error( io, &e ); +  Pike_sp--;    push_string(s);    } else {    CALL_AND_UNSET_ONERROR(e); -  push_int(0); +  Pike_sp[-1].u.integer = 0;    }    }   
1621:    if( require_whitespace )    whites = require_whitespace->u.integer;    +  Pike_sp-=args;    if( !parse_json_pcharp )    parse_json_pcharp = PIKE_MODULE_IMPORT(Standards.JSON, parse_json_pcharp );    retry:
1683:    *! @example    *! @code    *! // get the next whitespace separated word from the buffer. -  *! buffer->match("%*[ \t\r\n]%*[^ \t\r\n]"); +  *! buffer->match("%*[ \t\r\n]%[^ \t\r\n]");    *! @endcode    */    PIKEFUN string(0..255)|int|float|array match( string format )
1754:    */    PIKEFUN int(-1..) consume( int n )    { +  Pike_sp--;    if( !io_avail( THIS, n ) )    push_int(-1);    else
1779:    */    PIKEFUN int(-1..) unread( int bytes )    { +  Pike_sp--;    push_int64( io_rewind( THIS, bytes ) );    }   
1791:    PIKEFUN string(0..255) read( int bytes )    {    struct pike_string *s; +  Pike_sp--;    s = io_read_string(THIS, bytes );    if( s ) -  RETURN s; +  push_string( s ); +  else    push_undefined();    }   
1810:    {    struct pike_string * s = io_read_string(THIS, io_len(THIS));    if( s ) -  RETURN s; +  push_string( s ); +  else    push_undefined();    }   
1875:    IOBuffer *io = THIS;    struct object *o;    -  pop_stack(); +  Pike_sp--;       if( len < SIZEOF_INT_TYPE-1 ) /* will for sure fit. */    {
1907:    struct object *o;    struct array *a;    -  pop_n_elems(2); +  Pike_sp-=2;       if( !io_avail_mul( io, num, len ) )    {