]> git.ipfire.org Git - thirdparty/libarchive.git/commit
Fix & optimize string conversion functions for Windows (#2226)
authorDuncan Horn <40036384+dunhor@users.noreply.github.com>
Thu, 20 Jun 2024 21:01:47 +0000 (14:01 -0700)
committerGitHub <noreply@github.com>
Thu, 20 Jun 2024 21:01:47 +0000 (23:01 +0200)
commit56e023631298f6b4988c5ca1c04a45857b886e91
tree25c58036e9d9fa4f49eb81efbd0c7e0050fa7de0
parent5ec2b8446289dcaf328288804e19f9457ca4ef76
Fix & optimize string conversion functions for Windows (#2226)

All three parts of this change effectively stem from the same
assumption: most of the code in `archive_string.c` assumes that MBS <->
UTF-8 string conversion can be done directly and efficiently. This is
not quite true on Windows, where conversion looks more like MBS <-> WCS
<-> UTF-8. This results in a few inefficiencies currently present in the
code.

First, if the caller is asking for either the MBS or UTF-8 string, but
it's not currently set on the `archive_mstring`, then on Windows, it's
more efficient to first check if the WCS is set and do the conversion
with that. Otherwise, we'll end up doing a wasteful intermediate step of
converting either the MBS or UTF-8 string to WCS, which we already have.

Second, in the `archive_mstring_update_utf8` function, it's more
efficient on Windows to first convert to WCS and use that result to
convert to MBS, as opposed to the fallback I introduced in a previous
change, which converts UTF-8 to MBS first and disposes of the
intermediate WCS, only to re-calculate it.
libarchive/archive_string.c
libarchive/test/test_archive_string_conversion.c