pike.git / src / stralloc.c

version» Context lines:

pike.git/src/stralloc.c:1:   /*   || 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: stralloc.c,v 1.164 2004/03/24 20:19:23 grubba Exp $ + || $Id: stralloc.c,v 1.165 2004/04/15 17:34:40 mast Exp $   */      #include "global.h"   #include "stralloc.h"   #include "pike_macros.h"   #include "dynamic_buffer.h"   #include "pike_macros.h"   #include "pike_memory.h"   #include "pike_error.h"   #include "gc.h"
pike.git/src/stralloc.c:17:   #include "bignum.h"   #include "interpret.h"   #include "block_alloc.h"   #include "operators.h"      #include <errno.h>   #include <float.h>   #include <ctype.h>   #include <math.h>    - RCSID("$Id: stralloc.c,v 1.164 2004/03/24 20:19:23 grubba Exp $"); + RCSID("$Id: stralloc.c,v 1.165 2004/04/15 17:34:40 mast Exp $");      /* #define STRALLOC_USE_PRIMES */      #ifdef STRALLOC_USE_PRIMES      #define SET_HSIZE(X) htable_size=hashprimes[(X)]   #define HMODULO(X) ((X) % htable_size)      #else   
pike.git/src/stralloc.c:1972:      PMOD_EXPORT void init_string_builder_copy(struct string_builder *to,    struct string_builder *from)   {    to->malloced = from->malloced;    to->s = begin_wide_shared_string (from->s->len, from->s->size_shift);    MEMCPY (to->s->str, from->s->str, from->s->len << from->s->size_shift);    to->known_shift = from->known_shift;   }    - static void string_build_mkspace(struct string_builder *s, + /* str becomes invalid if successful (i.e. nonzero returned), +  * otherwise nothing happens. */ + PMOD_EXPORT int init_string_builder_with_string (struct string_builder *s, +  struct pike_string *str) + { +  if (str->refs == 1 && str->len > SHORT_STRING_THRESHOLD) { +  /* Unlink the string and use it as buffer directly. */ +  unlink_pike_string (str); +  s->s = str; +  s->malloced = str->len; +  s->known_shift = str->size_shift; +  return 1; +  } +  return 0; + } +  + PMOD_EXPORT void string_build_mkspace(struct string_builder *s,    ptrdiff_t chars, int mag)   {    if(mag > s->s->size_shift)    {    struct pike_string *n;    ptrdiff_t l = s->s->len + chars + s->malloced;    n=begin_wide_shared_string(l,mag);    pike_string_cpy(MKPCHARP_STR(n),s->s);    n->len=s->s->len;    s->s->len = s->malloced; /* Restore the real length */    really_free_pike_string(s->s);    s->malloced=l;    s->s=n;    } -  else if(((size_t)s->s->len+chars) > ((size_t)s->malloced)) +  else if(s->s->len+chars > s->malloced)    { -  size_t newlen = MAXIMUM((size_t)(s->malloced*2), -  (size_t)(s->s->len + chars)); +  ptrdiff_t newlen = MAXIMUM(s->malloced*2, +  s->s->len + chars);    ptrdiff_t oldlen = s->s->len;       s->s->len = s->malloced; /* Restore the real length */    s->s = realloc_unlinked_string(s->s, newlen);    s->s->len = oldlen;    s->malloced = newlen;    }   }      PMOD_EXPORT void *string_builder_allocate(struct string_builder *s, ptrdiff_t chars, int mag)