diff options
| author | Paul Eggert | 2017-06-04 23:52:10 -0700 |
|---|---|---|
| committer | Paul Eggert | 2017-06-04 23:53:47 -0700 |
| commit | cef90102cb0366f26a9cf618497793d223d60a66 (patch) | |
| tree | d710befc0730116053bbba8ba5ee32f104300a48 /src | |
| parent | 24f011d56aec273847181f9befbad491deb2f67e (diff) | |
| download | emacs-cef90102cb0366f26a9cf618497793d223d60a66.tar.gz emacs-cef90102cb0366f26a9cf618497793d223d60a66.zip | |
SCHARS and STRING_BYTES are nonnegative
Tell the compiler that SCHARS and STRING_BYTES are nonnegative, in
the hopes that this will optimize a bit better. Also, check this
at runtime if ENABLE_CHECKING.
* src/lisp.h (SCHARS, STRING_BYTES):
eassume that these functions return nonnegative values.
(STRING_SET_CHARS) [ENABLE_CHECKING]:
eassert that newsize is nonnegative.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lisp.h | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/lisp.h b/src/lisp.h index ce939fcee62..c35bd1f6df1 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -1346,7 +1346,9 @@ SSET (Lisp_Object string, ptrdiff_t index, unsigned char new) | |||
| 1346 | INLINE ptrdiff_t | 1346 | INLINE ptrdiff_t |
| 1347 | SCHARS (Lisp_Object string) | 1347 | SCHARS (Lisp_Object string) |
| 1348 | { | 1348 | { |
| 1349 | return XSTRING (string)->size; | 1349 | ptrdiff_t nchars = XSTRING (string)->size; |
| 1350 | eassume (0 <= nchars); | ||
| 1351 | return nchars; | ||
| 1350 | } | 1352 | } |
| 1351 | 1353 | ||
| 1352 | #ifdef GC_CHECK_STRING_BYTES | 1354 | #ifdef GC_CHECK_STRING_BYTES |
| @@ -1356,10 +1358,12 @@ INLINE ptrdiff_t | |||
| 1356 | STRING_BYTES (struct Lisp_String *s) | 1358 | STRING_BYTES (struct Lisp_String *s) |
| 1357 | { | 1359 | { |
| 1358 | #ifdef GC_CHECK_STRING_BYTES | 1360 | #ifdef GC_CHECK_STRING_BYTES |
| 1359 | return string_bytes (s); | 1361 | ptrdiff_t nbytes = string_bytes (s); |
| 1360 | #else | 1362 | #else |
| 1361 | return s->size_byte < 0 ? s->size : s->size_byte; | 1363 | ptrdiff_t nbytes = s->size_byte < 0 ? s->size : s->size_byte; |
| 1362 | #endif | 1364 | #endif |
| 1365 | eassume (0 <= nbytes); | ||
| 1366 | return nbytes; | ||
| 1363 | } | 1367 | } |
| 1364 | 1368 | ||
| 1365 | INLINE ptrdiff_t | 1369 | INLINE ptrdiff_t |
| @@ -1373,7 +1377,7 @@ STRING_SET_CHARS (Lisp_Object string, ptrdiff_t newsize) | |||
| 1373 | /* This function cannot change the size of data allocated for the | 1377 | /* This function cannot change the size of data allocated for the |
| 1374 | string when it was created. */ | 1378 | string when it was created. */ |
| 1375 | eassert (STRING_MULTIBYTE (string) | 1379 | eassert (STRING_MULTIBYTE (string) |
| 1376 | ? newsize <= SBYTES (string) | 1380 | ? 0 <= newsize && newsize <= SBYTES (string) |
| 1377 | : newsize == SCHARS (string)); | 1381 | : newsize == SCHARS (string)); |
| 1378 | XSTRING (string)->size = newsize; | 1382 | XSTRING (string)->size = newsize; |
| 1379 | } | 1383 | } |