diff options
| author | Gerd Moellmann | 2000-07-18 14:38:20 +0000 |
|---|---|---|
| committer | Gerd Moellmann | 2000-07-18 14:38:20 +0000 |
| commit | 5c5fecb38d6c3566846231e31018a5810ec43b97 (patch) | |
| tree | 34a1d83810497181f60adf36c651ca5f129aa12e /src/alloc.c | |
| parent | 22ab2303d9a6e3c3f4bf2319ed604d09ce7624ac (diff) | |
| download | emacs-5c5fecb38d6c3566846231e31018a5810ec43b97.tar.gz emacs-5c5fecb38d6c3566846231e31018a5810ec43b97.zip | |
(allocate_string_data): If string had already data
assigned, copy old contents to new string data.
Diffstat (limited to 'src/alloc.c')
| -rw-r--r-- | src/alloc.c | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/src/alloc.c b/src/alloc.c index 480a30ace51..4dc0b8165fa 100644 --- a/src/alloc.c +++ b/src/alloc.c | |||
| @@ -1029,9 +1029,9 @@ allocate_string_data (s, nchars, nbytes) | |||
| 1029 | struct Lisp_String *s; | 1029 | struct Lisp_String *s; |
| 1030 | int nchars, nbytes; | 1030 | int nchars, nbytes; |
| 1031 | { | 1031 | { |
| 1032 | struct sdata *data; | 1032 | struct sdata *data, *old_data; |
| 1033 | struct sblock *b; | 1033 | struct sblock *b; |
| 1034 | int needed; | 1034 | int needed, old_nbytes; |
| 1035 | 1035 | ||
| 1036 | /* Determine the number of bytes needed to store NBYTES bytes | 1036 | /* Determine the number of bytes needed to store NBYTES bytes |
| 1037 | of string data. */ | 1037 | of string data. */ |
| @@ -1077,16 +1077,9 @@ allocate_string_data (s, nchars, nbytes) | |||
| 1077 | } | 1077 | } |
| 1078 | else | 1078 | else |
| 1079 | b = current_sblock; | 1079 | b = current_sblock; |
| 1080 | 1080 | ||
| 1081 | /* If S had already data assigned, mark that as free by setting | 1081 | old_data = s->data ? SDATA_OF_STRING (s) : NULL; |
| 1082 | its string back-pointer to null, and recording the size of | 1082 | old_nbytes = GC_STRING_BYTES (s); |
| 1083 | the data in it.. */ | ||
| 1084 | if (s->data) | ||
| 1085 | { | ||
| 1086 | data = SDATA_OF_STRING (s); | ||
| 1087 | data->u.nbytes = GC_STRING_BYTES (s); | ||
| 1088 | data->string = NULL; | ||
| 1089 | } | ||
| 1090 | 1083 | ||
| 1091 | data = b->next_free; | 1084 | data = b->next_free; |
| 1092 | data->string = s; | 1085 | data->string = s; |
| @@ -1096,6 +1089,16 @@ allocate_string_data (s, nchars, nbytes) | |||
| 1096 | s->data[nbytes] = '\0'; | 1089 | s->data[nbytes] = '\0'; |
| 1097 | b->next_free = (struct sdata *) ((char *) data + needed); | 1090 | b->next_free = (struct sdata *) ((char *) data + needed); |
| 1098 | 1091 | ||
| 1092 | /* If S had already data assigned, mark that as free by setting its | ||
| 1093 | string back-pointer to null, and recording the size of the data | ||
| 1094 | in it.. Copy old string contents to the new sdata. */ | ||
| 1095 | if (old_data) | ||
| 1096 | { | ||
| 1097 | bcopy (old_data->u.data, s->data, old_nbytes); | ||
| 1098 | old_data->u.nbytes = old_nbytes; | ||
| 1099 | old_data->string = NULL; | ||
| 1100 | } | ||
| 1101 | |||
| 1099 | consing_since_gc += needed; | 1102 | consing_since_gc += needed; |
| 1100 | } | 1103 | } |
| 1101 | 1104 | ||