facebook / facebook/zstd

Consider unifying inline macros

Open
#2,461 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
C
Stars
27.9k
Forks
2.6k
Avg merge
1d 3h
Merged PRs (30d)
8

Description

There are three inline macros, `HINT_INLINE`, `MEM_STATIC`, `FORCE_INLINE_TEMPLATE`.

It would be nice they can be unified, such as:
* `HINT_INLINE`, only add `inline` keyword.
* `FORCE_INLINE`, force inline.
* `EXPAND_INLINE`, when `ZSTD_LIB_MINIFY` macro **is not** defined, it forces inline function; when `ZSTD_LIB_MINIFY` macro **is** defined, it's empty (no inline).

BTW, `HINT_INLINE` is force inline currently, the name is a bit confusing.
```c
/**
* HINT_INLINE is used to help the compiler generate better code. It is *not*
* used for "templates", so it can be tweaked based on the compilers
* performance.
*
* gcc-4.8 and gcc-4.9 have been shown to benefit from leaving off the
* always_inline attribute.
*
* clang up to 5.0.0 (trunk) benefit tremendously from the always_inline
* attribute.
*/
#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ >= 4 && __GNUC_MINOR__ >= 8 && __GNUC__ < 5
# define HINT_INLINE static INLINE_KEYWORD
#else
# define HINT_INLINE static INLINE_KEYWORD FORCE_INLINE_ATTR
#endif
```
These functions are using `HINT_INLINE`:

\lib\compress\zstd_compress_internal.h:
`ZSTD_storeSeq()`

\lib\decompress\huf_decompress.c:
`HUF_decodeStreamX1()`
`HUF_decodeStreamX2()`

\lib\decompress\zstd_decompress_block.c:
`ZSTD_overlapCopy8()`
`ZSTD_execSequence()`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.