mirror of
https://git.tukaani.org/xz.git
synced 2025-04-04 06:40:58 +00:00
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.
This commit is contained in:
parent
e82ee090c5
commit
bc14e4c94e
@ -161,7 +161,8 @@ dict_is_distance_valid(const lzma_dict *const dict, const size_t distance)
|
||||
|
||||
/// Repeat *len bytes at distance.
|
||||
static inline bool
|
||||
dict_repeat(lzma_dict *dict, uint32_t distance, uint32_t *len)
|
||||
dict_repeat(lzma_dict *restrict dict,
|
||||
uint32_t distance, uint32_t *restrict len)
|
||||
{
|
||||
// Don't write past the end of the dictionary.
|
||||
const size_t dict_avail = dict->limit - dict->pos;
|
||||
@ -195,7 +196,7 @@ dict_repeat(lzma_dict *dict, uint32_t distance, uint32_t *len)
|
||||
|
||||
|
||||
static inline void
|
||||
dict_put(lzma_dict *dict, uint8_t byte)
|
||||
dict_put(lzma_dict *restrict dict, uint8_t byte)
|
||||
{
|
||||
dict->buf[dict->pos++] = byte;
|
||||
|
||||
@ -207,7 +208,7 @@ dict_put(lzma_dict *dict, uint8_t byte)
|
||||
/// Puts one byte into the dictionary. Returns true if the dictionary was
|
||||
/// already full and the byte couldn't be added.
|
||||
static inline bool
|
||||
dict_put_safe(lzma_dict *dict, uint8_t byte)
|
||||
dict_put_safe(lzma_dict *restrict dict, uint8_t byte)
|
||||
{
|
||||
if (unlikely(dict->pos == dict->limit))
|
||||
return true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user