Mercurial > cpython-lru_cache-weakref
annotate Include/stringobject.h @ 13255:916fb024ce94 legacy-trunk
Change copyright notice.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Fri, 30 Jun 2000 23:50:40 +0000 |
| parents | 60fdb1db1175 |
| children | 87ee82e5c56d |
| rev | line source |
|---|---|
|
1329
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
1 #ifndef Py_STRINGOBJECT_H |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
2 #define Py_STRINGOBJECT_H |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
3 #ifdef __cplusplus |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
4 extern "C" { |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
5 #endif |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
6 |
| 145 | 7 /*********************************************************** |
| 2058 | 8 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
| 9 The Netherlands. | |
| 145 | 10 |
| 11 All Rights Reserved | |
| 12 | |
|
13255
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
9586
diff
changeset
|
13 Copyright (c) 2000, BeOpen.com. |
|
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
9586
diff
changeset
|
14 Copyright (c) 1995-2000, Corporation for National Research Initiatives. |
|
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
9586
diff
changeset
|
15 Copyright (c) 1990-1995, Stichting Mathematisch Centrum. |
|
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
9586
diff
changeset
|
16 All rights reserved. |
| 145 | 17 |
|
13255
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
9586
diff
changeset
|
18 See the file "Misc/COPYRIGHT" for information on usage and |
|
916fb024ce94
Change copyright notice.
Guido van Rossum <guido@python.org>
parents:
9586
diff
changeset
|
19 redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 145 | 20 |
| 21 ******************************************************************/ | |
| 22 | |
| 6 | 23 /* String object interface */ |
| 24 | |
| 25 /* | |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2058
diff
changeset
|
26 Type PyStringObject represents a character string. An extra zero byte is |
| 6 | 27 reserved at the end to ensure it is zero-terminated, but a size is |
| 28 present so strings with null bytes in them can be represented. This | |
| 29 is an immutable object type. | |
| 30 | |
| 31 There are functions to create new string objects, to test | |
| 32 an object for string-ness, and to get the | |
| 33 string value. The latter function returns a null pointer | |
| 34 if the object is not of the proper type. | |
| 35 There is a variant that takes an explicit size as well as a | |
| 36 variant that assumes a zero-terminated string. Note that none of the | |
| 37 functions should be applied to nil objects. | |
| 38 */ | |
| 39 | |
|
5003
65aace2012e5
Two speedup hacks. Caching the hash saves recalculation of a string's
Guido van Rossum <guido@python.org>
parents:
4897
diff
changeset
|
40 /* Two speedup hacks. Caching the hash saves recalculation of a |
|
65aace2012e5
Two speedup hacks. Caching the hash saves recalculation of a string's
Guido van Rossum <guido@python.org>
parents:
4897
diff
changeset
|
41 string's hash value. Interning strings (which requires hash |
|
65aace2012e5
Two speedup hacks. Caching the hash saves recalculation of a string's
Guido van Rossum <guido@python.org>
parents:
4897
diff
changeset
|
42 caching) tries to ensure that only one string object with a given |
|
65aace2012e5
Two speedup hacks. Caching the hash saves recalculation of a string's
Guido van Rossum <guido@python.org>
parents:
4897
diff
changeset
|
43 value exists, so equality tests are one pointer comparison. |
|
65aace2012e5
Two speedup hacks. Caching the hash saves recalculation of a string's
Guido van Rossum <guido@python.org>
parents:
4897
diff
changeset
|
44 Together, these can speed the interpreter up by as much as 20%. |
|
65aace2012e5
Two speedup hacks. Caching the hash saves recalculation of a string's
Guido van Rossum <guido@python.org>
parents:
4897
diff
changeset
|
45 Each costs the size of a long or pointer per string object. In |
|
65aace2012e5
Two speedup hacks. Caching the hash saves recalculation of a string's
Guido van Rossum <guido@python.org>
parents:
4897
diff
changeset
|
46 addition, interned strings live until the end of times. If you are |
|
65aace2012e5
Two speedup hacks. Caching the hash saves recalculation of a string's
Guido van Rossum <guido@python.org>
parents:
4897
diff
changeset
|
47 concerned about memory footprint, simply comment the #define out |
|
65aace2012e5
Two speedup hacks. Caching the hash saves recalculation of a string's
Guido van Rossum <guido@python.org>
parents:
4897
diff
changeset
|
48 here (and rebuild everything!). */ |
|
3833
f0efff28a24d
Turn on CACHE_HASH, for 2% speedier dict lookups
Guido van Rossum <guido@python.org>
parents:
2436
diff
changeset
|
49 #define CACHE_HASH |
|
5003
65aace2012e5
Two speedup hacks. Caching the hash saves recalculation of a string's
Guido van Rossum <guido@python.org>
parents:
4897
diff
changeset
|
50 #ifdef CACHE_HASH |
|
65aace2012e5
Two speedup hacks. Caching the hash saves recalculation of a string's
Guido van Rossum <guido@python.org>
parents:
4897
diff
changeset
|
51 #define INTERN_STRINGS |
|
65aace2012e5
Two speedup hacks. Caching the hash saves recalculation of a string's
Guido van Rossum <guido@python.org>
parents:
4897
diff
changeset
|
52 #endif |
|
3833
f0efff28a24d
Turn on CACHE_HASH, for 2% speedier dict lookups
Guido van Rossum <guido@python.org>
parents:
2436
diff
changeset
|
53 |
| 6 | 54 typedef struct { |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2058
diff
changeset
|
55 PyObject_VAR_HEAD |
|
1356
043da19302ef
Several optimizations and speed improvements.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1329
diff
changeset
|
56 #ifdef CACHE_HASH |
|
043da19302ef
Several optimizations and speed improvements.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1329
diff
changeset
|
57 long ob_shash; |
|
043da19302ef
Several optimizations and speed improvements.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1329
diff
changeset
|
58 #endif |
|
5003
65aace2012e5
Two speedup hacks. Caching the hash saves recalculation of a string's
Guido van Rossum <guido@python.org>
parents:
4897
diff
changeset
|
59 #ifdef INTERN_STRINGS |
|
65aace2012e5
Two speedup hacks. Caching the hash saves recalculation of a string's
Guido van Rossum <guido@python.org>
parents:
4897
diff
changeset
|
60 PyObject *ob_sinterned; |
|
65aace2012e5
Two speedup hacks. Caching the hash saves recalculation of a string's
Guido van Rossum <guido@python.org>
parents:
4897
diff
changeset
|
61 #endif |
| 6 | 62 char ob_sval[1]; |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2058
diff
changeset
|
63 } PyStringObject; |
| 6 | 64 |
|
2436
fa98dda07877
make the type a parameter of the DL_IMPORT macro, for Borland C
Guido van Rossum <guido@python.org>
parents:
2146
diff
changeset
|
65 extern DL_IMPORT(PyTypeObject) PyString_Type; |
| 6 | 66 |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2058
diff
changeset
|
67 #define PyString_Check(op) ((op)->ob_type == &PyString_Type) |
| 6 | 68 |
|
9586
60fdb1db1175
Add DL_IMPORT(returntype) for all officially exported functions.
Guido van Rossum <guido@python.org>
parents:
5003
diff
changeset
|
69 extern DL_IMPORT(PyObject *) PyString_FromStringAndSize Py_PROTO((const char *, int)); |
|
60fdb1db1175
Add DL_IMPORT(returntype) for all officially exported functions.
Guido van Rossum <guido@python.org>
parents:
5003
diff
changeset
|
70 extern DL_IMPORT(PyObject *) PyString_FromString Py_PROTO((const char *)); |
|
60fdb1db1175
Add DL_IMPORT(returntype) for all officially exported functions.
Guido van Rossum <guido@python.org>
parents:
5003
diff
changeset
|
71 extern DL_IMPORT(int) PyString_Size Py_PROTO((PyObject *)); |
|
60fdb1db1175
Add DL_IMPORT(returntype) for all officially exported functions.
Guido van Rossum <guido@python.org>
parents:
5003
diff
changeset
|
72 extern DL_IMPORT(char *) PyString_AsString Py_PROTO((PyObject *)); |
|
60fdb1db1175
Add DL_IMPORT(returntype) for all officially exported functions.
Guido van Rossum <guido@python.org>
parents:
5003
diff
changeset
|
73 extern DL_IMPORT(void) PyString_Concat Py_PROTO((PyObject **, PyObject *)); |
|
60fdb1db1175
Add DL_IMPORT(returntype) for all officially exported functions.
Guido van Rossum <guido@python.org>
parents:
5003
diff
changeset
|
74 extern DL_IMPORT(void) PyString_ConcatAndDel Py_PROTO((PyObject **, PyObject *)); |
|
60fdb1db1175
Add DL_IMPORT(returntype) for all officially exported functions.
Guido van Rossum <guido@python.org>
parents:
5003
diff
changeset
|
75 extern DL_IMPORT(int) _PyString_Resize Py_PROTO((PyObject **, int)); |
|
60fdb1db1175
Add DL_IMPORT(returntype) for all officially exported functions.
Guido van Rossum <guido@python.org>
parents:
5003
diff
changeset
|
76 extern DL_IMPORT(PyObject *) PyString_Format Py_PROTO((PyObject *, PyObject *)); |
| 6 | 77 |
|
5003
65aace2012e5
Two speedup hacks. Caching the hash saves recalculation of a string's
Guido van Rossum <guido@python.org>
parents:
4897
diff
changeset
|
78 #ifdef INTERN_STRINGS |
|
9586
60fdb1db1175
Add DL_IMPORT(returntype) for all officially exported functions.
Guido van Rossum <guido@python.org>
parents:
5003
diff
changeset
|
79 extern DL_IMPORT(void) PyString_InternInPlace Py_PROTO((PyObject **)); |
|
60fdb1db1175
Add DL_IMPORT(returntype) for all officially exported functions.
Guido van Rossum <guido@python.org>
parents:
5003
diff
changeset
|
80 extern DL_IMPORT(PyObject *) PyString_InternFromString Py_PROTO((const char *)); |
|
5003
65aace2012e5
Two speedup hacks. Caching the hash saves recalculation of a string's
Guido van Rossum <guido@python.org>
parents:
4897
diff
changeset
|
81 #else |
|
65aace2012e5
Two speedup hacks. Caching the hash saves recalculation of a string's
Guido van Rossum <guido@python.org>
parents:
4897
diff
changeset
|
82 #define PyString_InternInPlace(p) |
|
65aace2012e5
Two speedup hacks. Caching the hash saves recalculation of a string's
Guido van Rossum <guido@python.org>
parents:
4897
diff
changeset
|
83 #define PyString_InternFromString(cp) PyString_FromString(cp) |
|
65aace2012e5
Two speedup hacks. Caching the hash saves recalculation of a string's
Guido van Rossum <guido@python.org>
parents:
4897
diff
changeset
|
84 #endif |
|
65aace2012e5
Two speedup hacks. Caching the hash saves recalculation of a string's
Guido van Rossum <guido@python.org>
parents:
4897
diff
changeset
|
85 |
| 6 | 86 /* Macro, trading safety for speed */ |
|
4897
90c21dde4284
added PyString_GET_SIZE macro
Barry Warsaw <barry@python.org>
parents:
4654
diff
changeset
|
87 #define PyString_AS_STRING(op) (((PyStringObject *)(op))->ob_sval) |
|
90c21dde4284
added PyString_GET_SIZE macro
Barry Warsaw <barry@python.org>
parents:
4654
diff
changeset
|
88 #define PyString_GET_SIZE(op) (((PyStringObject *)(op))->ob_size) |
|
1329
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
89 |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
90 #ifdef __cplusplus |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
91 } |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
92 #endif |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1252
diff
changeset
|
93 #endif /* !Py_STRINGOBJECT_H */ |
