diff options
| author | Mattias EngdegÄrd | 2020-04-07 10:10:04 +0200 |
|---|---|---|
| committer | Mattias EngdegÄrd | 2020-04-11 17:04:57 +0200 |
| commit | a79019c16b23f40c29509b6c0bf6f79d87f18c1e (patch) | |
| tree | 54586d19a1dc42b291095e87cb750dbadedcc615 /src | |
| parent | 1988ffbaed709dfc71126efbf06644476830f07e (diff) | |
| download | emacs-a79019c16b23f40c29509b6c0bf6f79d87f18c1e.tar.gz emacs-a79019c16b23f40c29509b6c0bf6f79d87f18c1e.zip | |
Allow ENCODE_FILE and DECODE_FILE to use no-copy conversion
They already did return their argument under some circumstances;
this change broadens it to further reduce allocation in common cases
(bug#40407).
* src/coding.c (convert_string_nocopy): New function.
(decode_file_name, encode_file_name): Use convert_string_nocopy.
* src/coding.h (ENCODE_FILE, DECODE_FILE): Note the nocopy semantics.
Diffstat (limited to 'src')
| -rw-r--r-- | src/coding.c | 29 | ||||
| -rw-r--r-- | src/coding.h | 4 |
2 files changed, 19 insertions, 14 deletions
diff --git a/src/coding.c b/src/coding.c index 9848f983a81..0daa390bc85 100644 --- a/src/coding.c +++ b/src/coding.c | |||
| @@ -9559,10 +9559,7 @@ code_convert_string (Lisp_Object string, Lisp_Object coding_system, | |||
| 9559 | 9559 | ||
| 9560 | 9560 | ||
| 9561 | /* Encode or decode STRING according to CODING_SYSTEM. | 9561 | /* Encode or decode STRING according to CODING_SYSTEM. |
| 9562 | Do not set Vlast_coding_system_used. | 9562 | Do not set Vlast_coding_system_used. */ |
| 9563 | |||
| 9564 | This function is called only from macros DECODE_FILE and | ||
| 9565 | ENCODE_FILE, thus we ignore character composition. */ | ||
| 9566 | 9563 | ||
| 9567 | Lisp_Object | 9564 | Lisp_Object |
| 9568 | code_convert_string_norecord (Lisp_Object string, Lisp_Object coding_system, | 9565 | code_convert_string_norecord (Lisp_Object string, Lisp_Object coding_system, |
| @@ -10332,6 +10329,16 @@ DEFUN ("internal-decode-string-utf-8", Finternal_decode_string_utf_8, | |||
| 10332 | 10329 | ||
| 10333 | #endif /* ENABLE_UTF_8_CONVERTER_TEST */ | 10330 | #endif /* ENABLE_UTF_8_CONVERTER_TEST */ |
| 10334 | 10331 | ||
| 10332 | /* Encode or decode STRING using CODING_SYSTEM, with the possibility of | ||
| 10333 | returning STRING itself if it equals the result. | ||
| 10334 | Do not set Vlast_coding_system_used. */ | ||
| 10335 | static Lisp_Object | ||
| 10336 | convert_string_nocopy (Lisp_Object string, Lisp_Object coding_system, | ||
| 10337 | bool encodep) | ||
| 10338 | { | ||
| 10339 | return code_convert_string (string, coding_system, Qt, encodep, 1, 1); | ||
| 10340 | } | ||
| 10341 | |||
| 10335 | /* Encode or decode a file name, to or from a unibyte string suitable | 10342 | /* Encode or decode a file name, to or from a unibyte string suitable |
| 10336 | for passing to C library functions. */ | 10343 | for passing to C library functions. */ |
| 10337 | Lisp_Object | 10344 | Lisp_Object |
| @@ -10342,14 +10349,13 @@ decode_file_name (Lisp_Object fname) | |||
| 10342 | converts the file names either to UTF-16LE or to the system ANSI | 10349 | converts the file names either to UTF-16LE or to the system ANSI |
| 10343 | codepage internally, depending on the underlying OS; see w32.c. */ | 10350 | codepage internally, depending on the underlying OS; see w32.c. */ |
| 10344 | if (! NILP (Fcoding_system_p (Qutf_8))) | 10351 | if (! NILP (Fcoding_system_p (Qutf_8))) |
| 10345 | return code_convert_string_norecord (fname, Qutf_8, 0); | 10352 | return convert_string_nocopy (fname, Qutf_8, 0); |
| 10346 | return fname; | 10353 | return fname; |
| 10347 | #else /* !WINDOWSNT */ | 10354 | #else /* !WINDOWSNT */ |
| 10348 | if (! NILP (Vfile_name_coding_system)) | 10355 | if (! NILP (Vfile_name_coding_system)) |
| 10349 | return code_convert_string_norecord (fname, Vfile_name_coding_system, 0); | 10356 | return convert_string_nocopy (fname, Vfile_name_coding_system, 0); |
| 10350 | else if (! NILP (Vdefault_file_name_coding_system)) | 10357 | else if (! NILP (Vdefault_file_name_coding_system)) |
| 10351 | return code_convert_string_norecord (fname, | 10358 | return convert_string_nocopy (fname, Vdefault_file_name_coding_system, 0); |
| 10352 | Vdefault_file_name_coding_system, 0); | ||
| 10353 | else | 10359 | else |
| 10354 | return fname; | 10360 | return fname; |
| 10355 | #endif | 10361 | #endif |
| @@ -10369,14 +10375,13 @@ encode_file_name (Lisp_Object fname) | |||
| 10369 | converts the file names either to UTF-16LE or to the system ANSI | 10375 | converts the file names either to UTF-16LE or to the system ANSI |
| 10370 | codepage internally, depending on the underlying OS; see w32.c. */ | 10376 | codepage internally, depending on the underlying OS; see w32.c. */ |
| 10371 | if (! NILP (Fcoding_system_p (Qutf_8))) | 10377 | if (! NILP (Fcoding_system_p (Qutf_8))) |
| 10372 | return code_convert_string_norecord (fname, Qutf_8, 1); | 10378 | return convert_string_nocopy (fname, Qutf_8, 1); |
| 10373 | return fname; | 10379 | return fname; |
| 10374 | #else /* !WINDOWSNT */ | 10380 | #else /* !WINDOWSNT */ |
| 10375 | if (! NILP (Vfile_name_coding_system)) | 10381 | if (! NILP (Vfile_name_coding_system)) |
| 10376 | return code_convert_string_norecord (fname, Vfile_name_coding_system, 1); | 10382 | return convert_string_nocopy (fname, Vfile_name_coding_system, 1); |
| 10377 | else if (! NILP (Vdefault_file_name_coding_system)) | 10383 | else if (! NILP (Vdefault_file_name_coding_system)) |
| 10378 | return code_convert_string_norecord (fname, | 10384 | return convert_string_nocopy (fname, Vdefault_file_name_coding_system, 1); |
| 10379 | Vdefault_file_name_coding_system, 1); | ||
| 10380 | else | 10385 | else |
| 10381 | return fname; | 10386 | return fname; |
| 10382 | #endif | 10387 | #endif |
diff --git a/src/coding.h b/src/coding.h index 91856c5702b..c2a7b2a00ff 100644 --- a/src/coding.h +++ b/src/coding.h | |||
| @@ -642,11 +642,11 @@ struct coding_system | |||
| 642 | } while (false) | 642 | } while (false) |
| 643 | 643 | ||
| 644 | /* Encode the file name NAME using the specified coding system | 644 | /* Encode the file name NAME using the specified coding system |
| 645 | for file names, if any. */ | 645 | for file names, if any. May return NAME itself. */ |
| 646 | #define ENCODE_FILE(NAME) encode_file_name (NAME) | 646 | #define ENCODE_FILE(NAME) encode_file_name (NAME) |
| 647 | 647 | ||
| 648 | /* Decode the file name NAME using the specified coding system | 648 | /* Decode the file name NAME using the specified coding system |
| 649 | for file names, if any. */ | 649 | for file names, if any. May return NAME itself. */ |
| 650 | #define DECODE_FILE(NAME) decode_file_name (NAME) | 650 | #define DECODE_FILE(NAME) decode_file_name (NAME) |
| 651 | 651 | ||
| 652 | /* Encode the string STR using the specified coding system | 652 | /* Encode the string STR using the specified coding system |