Branch: Tag:

2009-09-09

2009-09-09 13:01:45 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Added optimization of has_value() and search() for single-character strings.
Thanks to Arjan van Staalduijnen <Arjan.van.Staalduijnen@rtl.nl> for the suggestion.

Rev: src/builtin_functions.c:1.693

2:   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: builtin_functions.c,v 1.692 2009/08/26 15:50:31 grubba Exp $ + || $Id: builtin_functions.c,v 1.693 2009/09/09 13:01:45 grubba Exp $   */      #include "global.h"
901:    "Start must not be greater than the "    "length of the string.\n");    -  if(Pike_sp[1-args].type == T_STRING) { -  /* Handle searching for the empty string. */ -  if (Pike_sp[1-args].u.string->len) { -  start = string_search(haystack, -  Pike_sp[1-args].u.string, -  start); +  if ((Pike_sp[1-args].type == T_INT) || +  ((Pike_sp[1-args].type == T_STRING) && +  (Pike_sp[1-args].u.string->len == 1))) { +  INT_TYPE val; +  if (Pike_sp[1-args].type == T_INT) { +  val = Pike_sp[1-args].u.integer; +  } else { +  val = index_shared_string(Pike_sp[1-args].u.string, 0);    } -  } else if (Pike_sp[1-args].type == T_INT) { -  INT_TYPE val = Pike_sp[1-args].u.integer; +        switch(Pike_sp[-args].u.string->size_shift) {    case 0:
957:    if (start >= haystack->len) {    start = -1;    } +  } else if(Pike_sp[1-args].type == T_STRING) { +  /* Handle searching for the empty string. */ +  if (Pike_sp[1-args].u.string->len) { +  start = string_search(haystack, +  Pike_sp[1-args].u.string, +  start); +  }    } else {    SIMPLE_BAD_ARG_ERROR("search", 2, "string | int");    }