aboutsummaryrefslogtreecommitdiffstats
path: root/src/data.c
diff options
context:
space:
mode:
authorRichard Stallman2020-02-06 18:30:47 -0500
committerRichard Stallman2020-02-06 18:30:47 -0500
commitc4be80112556e06bd7e92138e44051cc8c62e709 (patch)
tree2392fb385569e10ad9d4d0ab2a48a1771131bf4e /src/data.c
parent53f0de5d7719b43f184ce1a910f14882aedc50bc (diff)
parent15814d0ccd95848a2a0513d93ab718a49b289598 (diff)
downloademacs-c4be80112556e06bd7e92138e44051cc8c62e709.tar.gz
emacs-c4be80112556e06bd7e92138e44051cc8c62e709.zip
Merge
Diffstat (limited to 'src/data.c')
-rw-r--r--src/data.c66
1 files changed, 25 insertions, 41 deletions
diff --git a/src/data.c b/src/data.c
index 56e363f16b6..fae9cee7db1 100644
--- a/src/data.c
+++ b/src/data.c
@@ -2293,61 +2293,45 @@ bool-vector. IDX starts at 0. */)
2293 } 2293 }
2294 else /* STRINGP */ 2294 else /* STRINGP */
2295 { 2295 {
2296 int c;
2297
2298 CHECK_IMPURE (array, XSTRING (array)); 2296 CHECK_IMPURE (array, XSTRING (array));
2299 if (idxval < 0 || idxval >= SCHARS (array)) 2297 if (idxval < 0 || idxval >= SCHARS (array))
2300 args_out_of_range (array, idx); 2298 args_out_of_range (array, idx);
2301 CHECK_CHARACTER (newelt); 2299 CHECK_CHARACTER (newelt);
2302 c = XFIXNAT (newelt); 2300 int c = XFIXNAT (newelt);
2301 ptrdiff_t idxval_byte;
2302 int prev_bytes;
2303 unsigned char workbuf[MAX_MULTIBYTE_LENGTH], *p0 = workbuf, *p1;
2303 2304
2304 if (STRING_MULTIBYTE (array)) 2305 if (STRING_MULTIBYTE (array))
2305 { 2306 {
2306 ptrdiff_t idxval_byte, nbytes;
2307 int prev_bytes, new_bytes;
2308 unsigned char workbuf[MAX_MULTIBYTE_LENGTH], *p0 = workbuf, *p1;
2309
2310 nbytes = SBYTES (array);
2311 idxval_byte = string_char_to_byte (array, idxval); 2307 idxval_byte = string_char_to_byte (array, idxval);
2312 p1 = SDATA (array) + idxval_byte; 2308 p1 = SDATA (array) + idxval_byte;
2313 prev_bytes = BYTES_BY_CHAR_HEAD (*p1); 2309 prev_bytes = BYTES_BY_CHAR_HEAD (*p1);
2314 new_bytes = CHAR_STRING (c, p0);
2315 if (prev_bytes != new_bytes)
2316 {
2317 /* We must relocate the string data. */
2318 ptrdiff_t nchars = SCHARS (array);
2319 USE_SAFE_ALLOCA;
2320 unsigned char *str = SAFE_ALLOCA (nbytes);
2321
2322 memcpy (str, SDATA (array), nbytes);
2323 allocate_string_data (XSTRING (array), nchars,
2324 nbytes + new_bytes - prev_bytes);
2325 memcpy (SDATA (array), str, idxval_byte);
2326 p1 = SDATA (array) + idxval_byte;
2327 memcpy (p1 + new_bytes, str + idxval_byte + prev_bytes,
2328 nbytes - (idxval_byte + prev_bytes));
2329 SAFE_FREE ();
2330 clear_string_char_byte_cache ();
2331 }
2332 while (new_bytes--)
2333 *p1++ = *p0++;
2334 } 2310 }
2335 else 2311 else if (SINGLE_BYTE_CHAR_P (c))
2336 { 2312 {
2337 if (! SINGLE_BYTE_CHAR_P (c))
2338 {
2339 ptrdiff_t i;
2340
2341 for (i = SBYTES (array) - 1; i >= 0; i--)
2342 if (SREF (array, i) >= 0x80)
2343 args_out_of_range (array, newelt);
2344 /* ARRAY is an ASCII string. Convert it to a multibyte
2345 string, and try `aset' again. */
2346 STRING_SET_MULTIBYTE (array);
2347 return Faset (array, idx, newelt);
2348 }
2349 SSET (array, idxval, c); 2313 SSET (array, idxval, c);
2314 return newelt;
2350 } 2315 }
2316 else
2317 {
2318 for (ptrdiff_t i = SBYTES (array) - 1; i >= 0; i--)
2319 if (!ASCII_CHAR_P (SREF (array, i)))
2320 args_out_of_range (array, newelt);
2321 /* ARRAY is an ASCII string. Convert it to a multibyte string. */
2322 STRING_SET_MULTIBYTE (array);
2323 idxval_byte = idxval;
2324 p1 = SDATA (array) + idxval_byte;
2325 prev_bytes = 1;
2326 }
2327
2328 int new_bytes = CHAR_STRING (c, p0);
2329 if (prev_bytes != new_bytes)
2330 p1 = resize_string_data (array, idxval_byte, prev_bytes, new_bytes);
2331
2332 do
2333 *p1++ = *p0++;
2334 while (--new_bytes != 0);
2351 } 2335 }
2352 2336
2353 return newelt; 2337 return newelt;