Branch: Tag:

2012-04-04

2012-04-04 07:57:19 by Stephen R. van den Berg <srb@cuci.nl>

Optimise optimisation and move inline int2string
from roxen.c to operators.c.

39:   #define OP_MODULO_BY_ZERO_ERROR(FUNC) \    math_error(FUNC, sp-2, 2, 0, "Modulo by zero.\n")    +  /* These calculations should always give some margin based on the size. */ +  /* One extra char for the sign. */ + #define MAX_INT_SPRINTF_LEN (1 + (SIZEOF_INT_TYPE * 5 + 1) / 2) +    /* The destructive multiset merge code is broken.    * l->msd gets -1 refs.    *
329:   /* Special case for casting to string. */   PMOD_EXPORT void o_cast_to_string(void)   { -  char buf[MAX_NUM_BUF]; +  struct pike_string *s; +     switch(TYPEOF(sp[-1]))    {    case T_OBJECT:
357:    LFUN__IS_TYPE);    if( f != -1)    { -  struct pike_string *s; +     REF_MAKE_CONST_STRING(s, "string");    push_string(s);    apply_low(o, f, 1);
376:    {    int i, alen;    struct array *a = sp[-1].u.array; -  struct pike_string *s; +     int shift = 0;    alen = a->size;   
440:    }    break;    } -  s = end_shared_string(s); +     pop_stack(); -  push_string(s); +  push_string(end_shared_string(s));    }    return;   
453:    return;       case T_FLOAT: +  { +  char buf[MAX_FLOAT_SPRINTF_LEN+1];    format_pike_float (buf, sp[-1].u.float_number); -  +  s = make_shared_string(buf);    break; -  +  }       case T_INT: -  sprintf(buf, "%"PRINTPIKEINT"d", sp[-1].u.integer); +  { +  INT_TYPE org; +  char buf[MAX_INT_SPRINTF_LEN]; +  register char*b = buf+sizeof buf-1; +  register unsigned INT_TYPE i; +  org = sp[-1].u.integer; +  *b-- = '\0'; +  i = org; +  +  if( org < 0 ) +  i = -i; +  +  goto jin; /* C as a macro assembler :-) */ +  do +  { +  i /= 10; + jin: *b-- = '0'+(i%10); +  } +  while( i >= 10 ); +  +  if( org < 0 ) +  *b = '-'; +  else +  b++; +  s = make_shared_string(b); +  }    break;    }    -  SET_SVAL(sp[-1], PIKE_T_STRING, 0, string, make_shared_string(buf)); +  SET_SVAL(sp[-1], PIKE_T_STRING, 0, string, s);   }      PMOD_EXPORT void o_cast(struct pike_type *type, INT32 run_time_type)