aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2020-01-17 23:59:52 -0800
committerPaul Eggert2020-01-18 00:02:12 -0800
commitac121d8c8f1863c0c1a0f3c8250518abfc26b2a9 (patch)
tree7e09d7970d81dc656b4431daeb647a3d6ec7f194 /src
parentc1b6d5c5b9f8eee8aa3a8071292e8b3281ecf28a (diff)
downloademacs-ac121d8c8f1863c0c1a0f3c8250518abfc26b2a9.tar.gz
emacs-ac121d8c8f1863c0c1a0f3c8250518abfc26b2a9.zip
Make Faset nonrecursive
* src/data.c (Faset): Refactor Faset so that it’s not recursive. This helps the compiler and makes the code a bit clearer.
Diffstat (limited to 'src')
-rw-r--r--src/data.c56
1 files changed, 28 insertions, 28 deletions
diff --git a/src/data.c b/src/data.c
index cd7db6a0bb9..fae9cee7db1 100644
--- a/src/data.c
+++ b/src/data.c
@@ -2293,45 +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 unsigned char workbuf[MAX_MULTIBYTE_LENGTH], *p0 = workbuf; 2307 idxval_byte = string_char_to_byte (array, idxval);
2307 ptrdiff_t idxval_byte = string_char_to_byte (array, idxval); 2308 p1 = SDATA (array) + idxval_byte;
2308 unsigned char *p1 = SDATA (array) + idxval_byte; 2309 prev_bytes = BYTES_BY_CHAR_HEAD (*p1);
2309
2310 int prev_bytes = BYTES_BY_CHAR_HEAD (*p1);
2311 int new_bytes = CHAR_STRING (c, p0);
2312 if (prev_bytes != new_bytes)
2313 p1 = resize_string_data (array, idxval_byte, prev_bytes, new_bytes);
2314
2315 do
2316 *p1++ = *p0++;
2317 while (--new_bytes != 0);
2318 } 2310 }
2319 else 2311 else if (SINGLE_BYTE_CHAR_P (c))
2320 { 2312 {
2321 if (! SINGLE_BYTE_CHAR_P (c))
2322 {
2323 ptrdiff_t i;
2324
2325 for (i = SBYTES (array) - 1; i >= 0; i--)
2326 if (SREF (array, i) >= 0x80)
2327 args_out_of_range (array, newelt);
2328 /* ARRAY is an ASCII string. Convert it to a multibyte
2329 string, and try `aset' again. */
2330 STRING_SET_MULTIBYTE (array);
2331 return Faset (array, idx, newelt);
2332 }
2333 SSET (array, idxval, c); 2313 SSET (array, idxval, c);
2314 return newelt;
2334 } 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);
2335 } 2335 }
2336 2336
2337 return newelt; 2337 return newelt;