-DEFINE_BASIC_LRECORD_IMPLEMENTATION ("string", string,
- mark_string, print_string,
- /*
- * No `finalize', or `hash' methods.
- * internal_hash already knows how
- * to hash strings and finalization
- * is done with the
- * ADDITIONAL_FREE_string macro,
- * which is the standard way to do
- * finalization when using
- * SWEEP_FIXED_TYPE_BLOCK().
- */
- 0, string_equal, 0,
- string_description,
- struct Lisp_String);
+/* We store the string's extent info as the first element of the string's
+ property list; and the string's MODIFF as the first or second element
+ of the string's property list (depending on whether the extent info
+ is present), but only if the string has been modified. This is ugly
+ but it reduces the memory allocated for the string in the vast
+ majority of cases, where the string is never modified and has no
+ extent info.
+
+ #### This means you can't use an int as a key in a string's plist. */
+
+static Lisp_Object *
+string_plist_ptr (Lisp_Object string)
+{
+ Lisp_Object *ptr = &XSTRING (string)->plist;
+
+ if (CONSP (*ptr) && EXTENT_INFOP (XCAR (*ptr)))
+ ptr = &XCDR (*ptr);
+ if (CONSP (*ptr) && INTP (XCAR (*ptr)))
+ ptr = &XCDR (*ptr);
+ return ptr;
+}
+
+static Lisp_Object
+string_getprop (Lisp_Object string, Lisp_Object property)
+{
+ return external_plist_get (string_plist_ptr (string), property, 0, ERROR_ME);
+}
+
+static int
+string_putprop (Lisp_Object string, Lisp_Object property, Lisp_Object value)
+{
+ external_plist_put (string_plist_ptr (string), property, value, 0, ERROR_ME);
+ return 1;
+}
+
+static int
+string_remprop (Lisp_Object string, Lisp_Object property)
+{
+ return external_remprop (string_plist_ptr (string), property, 0, ERROR_ME);
+}
+
+static Lisp_Object
+string_plist (Lisp_Object string)
+{
+ return *string_plist_ptr (string);
+}
+
+/* No `finalize', or `hash' methods.
+ internal_hash() already knows how to hash strings and finalization
+ is done with the ADDITIONAL_FREE_string macro, which is the
+ standard way to do finalization when using
+ SWEEP_FIXED_TYPE_BLOCK(). */
+DEFINE_BASIC_LRECORD_IMPLEMENTATION_WITH_PROPS ("string", string,
+ mark_string, print_string,
+ 0, string_equal, 0,
+ string_description,
+ string_getprop,
+ string_putprop,
+ string_remprop,
+ string_plist,
+ Lisp_String);