]> git.ipfire.org Git - thirdparty/xz.git/commit
liblzma: Add "restrict" to a few functions in lz_decoder.h
authorLasse Collin <lasse.collin@tukaani.org>
Tue, 25 Mar 2025 13:18:31 +0000 (15:18 +0200)
committerLasse Collin <lasse.collin@tukaani.org>
Tue, 25 Mar 2025 13:18:31 +0000 (15:18 +0200)
commitbc14e4c94e788d42eeab984298391fc0ca46f969
tree7d46280b273190352957134290ab8d4763ab4012
parente82ee090c567e560f51a056775a17f534d159d65
liblzma: Add "restrict" to a few functions in lz_decoder.h

This doesn't make any difference in practice because compilers can
already see that writing through the dict->buf pointer cannot modify
the contents of *dict itself: The LZMA decoder makes a local copy of
the lzma_dict structure, and even if it didn't, the pointer to
lzma_dict in the LZMA decoder is already "restrict".

It's nice to add "restrict" anyway. uint8_t is typically unsigned char
which can alias anything. Without the above conditions or "restrict",
compilers could need to assume that writing through dict->buf might
modify *dict. This would matter in dict_repeat() because the loops
refer to dict->buf and dict->pos instead of making local copies of
those members for the duration of the loops. If compilers had to
assume that writing through dict->buf can affect *dict, then compilers
would need to emit code that reloads dict->buf and dict->pos after
every write through dict->buf.
src/liblzma/lz/lz_decoder.h