improve cpp performance
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@7862 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
b67a93a3d6
commit
1c7786574f
3 changed files with 201 additions and 162 deletions
|
|
@ -65,6 +65,14 @@
|
|||
#define DohGetc DOH_NAMESPACE(Getc)
|
||||
#define DohPutc DOH_NAMESPACE(Putc)
|
||||
#define DohUngetc DOH_NAMESPACE(Ungetc)
|
||||
|
||||
#define DohStringGetc DOH_NAMESPACE(StringGetc)
|
||||
#define DohStringPutc DOH_NAMESPACE(StringPutc)
|
||||
#define DohStringUngetc DOH_NAMESPACE(StringUngetc)
|
||||
#define DohStringAppend DOH_NAMESPACE(StringAppend)
|
||||
|
||||
|
||||
|
||||
#define DohGetline DOH_NAMESPACE(Getline)
|
||||
#define DohSetline DOH_NAMESPACE(Setline)
|
||||
#define DohGetfile DOH_NAMESPACE(Getfile)
|
||||
|
|
@ -218,6 +226,8 @@ extern int DohGetc(DOHFile *obj);
|
|||
extern int DohPutc(int ch, DOHFile *obj);
|
||||
extern int DohUngetc(int ch, DOHFile *obj);
|
||||
|
||||
|
||||
|
||||
/* Iterators */
|
||||
extern DohIterator DohFirst(DOH *obj);
|
||||
extern DohIterator DohNext(DohIterator x);
|
||||
|
|
@ -234,6 +244,16 @@ extern void DohSetfile(DOH *obj, DOH *file);
|
|||
extern int DohReplace(DOHString *src, const DOHString_or_char *token, const DOHString_or_char *rep, int flags);
|
||||
extern void DohChop(DOHString *src);
|
||||
|
||||
extern int DohString_putc(DOH *so, int ch);
|
||||
extern int DohString_getc(DOH *so);
|
||||
extern int DohString_ungetc(DOH *so, int ch);
|
||||
extern void DohString_append(DOH *so, DOH *str);
|
||||
|
||||
#define DohStringPutc(ch,so) DohString_putc(so, ch)
|
||||
#define DohStringGetc(so) DohString_getc(so)
|
||||
#define DohStringUngetc(ch,so) DohString_ungetc(so, ch)
|
||||
#define DohStringAppend(so,str) DohString_append(so, str)
|
||||
|
||||
/* Meta-variables */
|
||||
extern DOH *DohGetmeta(DOH *, const DOH *);
|
||||
extern int DohSetmeta(DOH *, const DOH *, const DOH *value);
|
||||
|
|
@ -355,6 +375,12 @@ extern void DohMemoryDebug(void);
|
|||
#define Getc DohGetc
|
||||
#define Putc DohPutc
|
||||
#define Ungetc DohUngetc
|
||||
|
||||
#define StringGetc DohStringGetc
|
||||
#define StringPutc DohStringPutc
|
||||
#define StringUngetc DohStringUngetc
|
||||
#define StringAppend DohStringAppend
|
||||
|
||||
#define Close DohClose
|
||||
#define vPrintf DohvPrintf
|
||||
#define GetInt DohGetInt
|
||||
|
|
|
|||
|
|
@ -154,13 +154,16 @@ String_hash(DOH *so) {
|
|||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* static add(String *s, const char *newstr) - Append to s
|
||||
* DohString_append(String *s, const char *newstr) - Append to s
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
add(String *s, const char *newstr) {
|
||||
void
|
||||
DohString_append(DOH *so, DOH *str) {
|
||||
int oldlen, newlen, newmaxsize, l, i, sp;
|
||||
char *tc;
|
||||
String *s = (String *) ObjData(so);
|
||||
char *newstr = (char *) DohData(str);
|
||||
|
||||
if (!newstr) return;
|
||||
s->hashkey = -1;
|
||||
l = (int) strlen(newstr);
|
||||
|
|
@ -208,19 +211,21 @@ String_clear(DOH *so)
|
|||
static int
|
||||
String_insert(DOH *so, int pos, DOH *str)
|
||||
{
|
||||
String *s = (String *) ObjData(so);
|
||||
String *s;
|
||||
char *nstr;
|
||||
int len;
|
||||
char *data;
|
||||
|
||||
if (pos == DOH_END) {
|
||||
DohString_append(so, str);
|
||||
return 0;
|
||||
}
|
||||
|
||||
s = (String *) ObjData(so);
|
||||
s->hashkey = -1;
|
||||
data = (char *) DohData(str);
|
||||
nstr = s->str;
|
||||
|
||||
s->hashkey = -1;
|
||||
if (pos == DOH_END) {
|
||||
add(s, data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (pos < 0) pos = 0;
|
||||
else if (pos > s->len) pos = s->len;
|
||||
|
|
@ -417,8 +422,8 @@ String_tell(DOH *so)
|
|||
* int String_putc()
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
String_putc(DOH *so, int ch)
|
||||
int
|
||||
DohString_putc(DOH *so, int ch)
|
||||
{
|
||||
register int len, maxsize, sp;
|
||||
String *s = (String *) ObjData(so);
|
||||
|
|
@ -429,9 +434,9 @@ String_putc(DOH *so, int ch)
|
|||
register char *tc;
|
||||
maxsize = s->maxsize;
|
||||
if (len > (maxsize-2)) {
|
||||
s->str = (char *) DohRealloc(s->str,2*maxsize);
|
||||
s->str = (char *) DohRealloc(s->str,3*maxsize);
|
||||
assert(s->str);
|
||||
s->maxsize = 2*maxsize;
|
||||
s->maxsize = 3*maxsize;
|
||||
}
|
||||
tc = s->str + len;
|
||||
*(tc++) = ch;
|
||||
|
|
@ -452,8 +457,8 @@ String_putc(DOH *so, int ch)
|
|||
* int String_getc()
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
String_getc(DOH *so)
|
||||
int
|
||||
DohString_getc(DOH *so)
|
||||
{
|
||||
int c;
|
||||
String *s = (String *) ObjData(so);
|
||||
|
|
@ -469,8 +474,8 @@ String_getc(DOH *so)
|
|||
* int String_ungetc()
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
String_ungetc(DOH *so, int ch)
|
||||
int
|
||||
DohString_ungetc(DOH *so, int ch)
|
||||
{
|
||||
String *s = (String *) ObjData(so);
|
||||
if (ch == EOF) return ch;
|
||||
|
|
@ -480,7 +485,6 @@ String_ungetc(DOH *so, int ch)
|
|||
return ch;
|
||||
}
|
||||
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* replace_simple(String *str, char *token, char *rep, int flags, int count)
|
||||
*
|
||||
|
|
@ -882,9 +886,9 @@ static DohListMethods StringListMethods = {
|
|||
static DohFileMethods StringFileMethods = {
|
||||
String_read,
|
||||
String_write,
|
||||
String_putc,
|
||||
String_getc,
|
||||
String_ungetc,
|
||||
DohString_putc,
|
||||
DohString_getc,
|
||||
DohString_ungetc,
|
||||
String_seek,
|
||||
String_tell,
|
||||
0, /* close */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue