diff options
| author | Paul Eggert | 2014-09-09 23:38:38 -0700 |
|---|---|---|
| committer | Paul Eggert | 2014-09-09 23:38:38 -0700 |
| commit | 11e28ab08d44c1fc40e3e4dc728c14c521b3879d (patch) | |
| tree | fd5f541d44d9d3d6383f2064c9e45c684b73d6cf /src/alloc.c | |
| parent | c98d0ea46197545b899b463c1ba9ff2fea8e8c6e (diff) | |
| download | emacs-11e28ab08d44c1fc40e3e4dc728c14c521b3879d.tar.gz emacs-11e28ab08d44c1fc40e3e4dc728c14c521b3879d.zip | |
Improve the experimental local and scoped allocation.
* configure.ac (HAVE_STRUCT_ATTRIBUTE_ALIGNED)
(HAVE_STATEMENT_EXPRESSIONS): New configure-time checks.
* src/alloc.c (local_string_init, local_vector_init):
New functions, defined if USE_LOCAL_ALLOCATORS.
Mostly, these are moved here from lisp.h, as it's not
clear it's worth making them inline.
* src/lisp.h (USE_STACK_LISP_OBJECTS): Default to false.
(GCALIGNED): Depend on HAVE_STRUCT_ATTRIBUTE_ALIGNED and
USE_STACK_LISP_OBJECTS, not on a laundry list.
(local_string_init, local_vector_init): New decls.
(union Aligned_Cons): New type.
(scoped_cons): Use it. Give up on the char trick, as it's a too
much of a maintenance hassle; if someone wants this speedup
they'll just need to convince their compiler to align properly.
Conversely, use the speedup if struct Lisp_Cons happens to
be aligned even without a directive. Better yet, help it along
by using union Aligned_Cons rather than struct Lisp_Cons.
(pointer_valid_for_lisp_object): Remove. This check is not
necessary, since make_lisp_ptr is already doing it. All uses removed.
(local_vector_init, local_string_init): Move to alloc.c.
(build_local_vector): Remove this awkward macro, replacing with ...
(make_local_vector): New macro, which acts more like a function.
Use statement expressions and use __COUNTER__ to avoid macro
capture. Fall back on functions if these features are not supported.
(build_local_string, make_local_string): Likewise.
Diffstat (limited to 'src/alloc.c')
| -rw-r--r-- | src/alloc.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/alloc.c b/src/alloc.c index 5c7ce31cad8..714827f6ae3 100644 --- a/src/alloc.c +++ b/src/alloc.c | |||
| @@ -2226,6 +2226,32 @@ make_string (const char *contents, ptrdiff_t nbytes) | |||
| 2226 | return val; | 2226 | return val; |
| 2227 | } | 2227 | } |
| 2228 | 2228 | ||
| 2229 | #ifdef USE_LOCAL_ALLOCATORS | ||
| 2230 | |||
| 2231 | /* Initialize the string S from DATA and SIZE. S must be followed by | ||
| 2232 | SIZE + 1 bytes of memory that can be used. Return S tagged as a | ||
| 2233 | Lisp object. */ | ||
| 2234 | |||
| 2235 | Lisp_Object | ||
| 2236 | local_string_init (struct Lisp_String *s, char const *data, ptrdiff_t size) | ||
| 2237 | { | ||
| 2238 | unsigned char *data_copy = (unsigned char *) (s + 1); | ||
| 2239 | parse_str_as_multibyte ((unsigned char const *) data, | ||
| 2240 | size, &s->size, &s->size_byte); | ||
| 2241 | if (size == s->size || size != s->size_byte) | ||
| 2242 | { | ||
| 2243 | s->size = size; | ||
| 2244 | s->size_byte = -1; | ||
| 2245 | } | ||
| 2246 | s->intervals = NULL; | ||
| 2247 | s->data = data_copy; | ||
| 2248 | memcpy (data_copy, data, size); | ||
| 2249 | data_copy[size] = '\0'; | ||
| 2250 | return make_lisp_ptr (s, Lisp_String); | ||
| 2251 | } | ||
| 2252 | |||
| 2253 | #endif | ||
| 2254 | |||
| 2229 | 2255 | ||
| 2230 | /* Make an unibyte string from LENGTH bytes at CONTENTS. */ | 2256 | /* Make an unibyte string from LENGTH bytes at CONTENTS. */ |
| 2231 | 2257 | ||
| @@ -3288,6 +3314,22 @@ See also the function `vector'. */) | |||
| 3288 | return vector; | 3314 | return vector; |
| 3289 | } | 3315 | } |
| 3290 | 3316 | ||
| 3317 | #ifdef USE_LOCAL_ALLOCATORS | ||
| 3318 | |||
| 3319 | /* Initialize V with LENGTH objects each with value INIT, | ||
| 3320 | and return it tagged as a Lisp Object. */ | ||
| 3321 | |||
| 3322 | INLINE Lisp_Object | ||
| 3323 | local_vector_init (struct Lisp_Vector *v, ptrdiff_t length, Lisp_Object init) | ||
| 3324 | { | ||
| 3325 | v->header.size = length; | ||
| 3326 | for (ptrdiff_t i = 0; i < length; i++) | ||
| 3327 | v->contents[i] = init; | ||
| 3328 | return make_lisp_ptr (v, Lisp_Vectorlike); | ||
| 3329 | } | ||
| 3330 | |||
| 3331 | #endif | ||
| 3332 | |||
| 3291 | 3333 | ||
| 3292 | DEFUN ("vector", Fvector, Svector, 0, MANY, 0, | 3334 | DEFUN ("vector", Fvector, Svector, 0, MANY, 0, |
| 3293 | doc: /* Return a newly created vector with specified arguments as elements. | 3335 | doc: /* Return a newly created vector with specified arguments as elements. |