Turn GS_REPLACE_CONSTANT_STRING into a no-op with the new ABI.

With the classic GCC / NeXT ABI, NSConstantString is a simple pair of a
length and a buffer.  This means that calling -hash calculates the hash
each call, which makes it expensive to use constant strings as
dictionary keys.  The GS_REPLACE_CONSTANT_STRING macro replaces a
constant string with an immutable NSString object, which has an instance
variable for storing the hash.

With the new ABI, NSConstantString has a different layout that includes
space for a hash.  This means that there is no advantage in replacing it
with an NSString (and there is a disadvantage in that it now requires
memory allocation and can be accidentally deallocated), so don't do it.
This commit is contained in:
David Chisnall 2019-01-02 17:00:47 +00:00
parent 2da172bf4e
commit df3eed2452

View file

@ -185,8 +185,16 @@ __attribute__((unused)) static void GSFreeTempBuffer(void **b)
* Yet the optimization of the stored hash value is currently deemed
* more important.
*/
#ifndef GNUSTEP_NEW_STRING_ABI
#define GS_REPLACE_CONSTANT_STRING(ID) [(ID = [NSObject \
leak: [[NSString alloc] initWithUTF8String: [ID UTF8String]]]) release]
#else
/**
* In the new constant string ABI, the hash can be stored in the constant
* string object, so this is not a problem.
*/
#define GS_REPLACE_CONSTANT_STRING(ID)
#endif
/* Using cString here is OK here
because NXConstantString returns a pointer
to it's internal pointer. */