pike.git
/
src
/
builtin.cmod
version
»
Context lines:
10
20
40
80
file
none
3
pike.git/src/builtin.cmod:1:
/* -*- c -*-
-
* $Id: builtin.cmod,v 1.
64
2001/09/
05
23
:
44
:
32
hubbe
Exp $
+
* $Id: builtin.cmod,v 1.
65
2001/09/
21
17
:
57
:
12
grubba
Exp $
*/ #include "global.h" #include "interpret.h" #include "svalue.h" #include "opcodes.h" #include "pike_macros.h" #include "object.h" #include "program.h" #include "array.h"
pike.git/src/builtin.cmod:1375:
/*! @decl void add(string ... data) *! *! Adds @[data] to the buffer. Returns the size of the buffer. *! */ PIKEFUN int add( string ... arg1 ) { struct Buffer_struct *str = THIS; int j;
-
struct pike_string *a;
+
-
+
if (!str->str.s && args) {
+
int sum = 0;
+
int shift = 0;
+
for (j=0; j < args; j++) {
+
struct pike_string *a = Pike_sp[j-args].u.string;
+
sum += a->len;
+
shift |= a->size_shift;
+
}
+
if (sum < str->initial) {
+
sum = str->initial;
+
}
+
init_string_builder_alloc(&str->str, sum, shift & ~(shift>>1));
+
}
+
for( j = 0; j<args; j++ ) {
-
a = Pike_sp[-
args+j
].u.string;
-
if( !str->str.s )
-
init_string_builder_alloc( &str->str, str->initial, a->size_shift );
+
struct pike_string *
a = Pike_sp[
j
-
args
].u.string;
string_builder_shared_strcat( &str->str, a ); }
-
RETURN
str->str.s->len;
+
+
if (str->str.s) {
+
RETURN str->str.s->len;
+
} else {
+
RETURN 0;
}
-
+
}
/*! @decl string get_copy() *! *! Get the data from the buffer. Significantly slower than @[get], *! but does not clear the buffer. */ PIKEFUN string get_copy() { struct pike_string *str = THIS->str.s; if( str )