1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-03 10:31:37 -08:00

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.
This commit is contained in:
Paul Eggert 2017-06-04 23:52:10 -07:00
parent 24f011d56a
commit cef90102cb

View file

@ -1346,7 +1346,9 @@ SSET (Lisp_Object string, ptrdiff_t index, unsigned char new)
INLINE ptrdiff_t
SCHARS (Lisp_Object string)
{
return XSTRING (string)->size;
ptrdiff_t nchars = XSTRING (string)->size;
eassume (0 <= nchars);
return nchars;
}
#ifdef GC_CHECK_STRING_BYTES
@ -1356,10 +1358,12 @@ INLINE ptrdiff_t
STRING_BYTES (struct Lisp_String *s)
{
#ifdef GC_CHECK_STRING_BYTES
return string_bytes (s);
ptrdiff_t nbytes = string_bytes (s);
#else
return s->size_byte < 0 ? s->size : s->size_byte;
ptrdiff_t nbytes = s->size_byte < 0 ? s->size : s->size_byte;
#endif
eassume (0 <= nbytes);
return nbytes;
}
INLINE ptrdiff_t
@ -1373,7 +1377,7 @@ STRING_SET_CHARS (Lisp_Object string, ptrdiff_t newsize)
/* This function cannot change the size of data allocated for the
string when it was created. */
eassert (STRING_MULTIBYTE (string)
? newsize <= SBYTES (string)
? 0 <= newsize && newsize <= SBYTES (string)
: newsize == SCHARS (string));
XSTRING (string)->size = newsize;
}