basic,shared: mark eligible functions with _pure_/_const_
Following the recent witch hunt done to static inline functions I figure we should at least give the compiler some more hint on optimizations.
This commit is contained in:
+3
-3
@@ -8,7 +8,7 @@ int af_from_name(const char *name) _pure_;
|
||||
|
||||
const char* af_to_name_short(int id) _const_;
|
||||
|
||||
const char* af_to_ipv4_ipv6(int id);
|
||||
int af_from_ipv4_ipv6(const char *af);
|
||||
const char* af_to_ipv4_ipv6(int id) _const_;
|
||||
int af_from_ipv4_ipv6(const char *af) _pure_;
|
||||
|
||||
int af_max(void);
|
||||
int af_max(void) _const_;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include "forward.h"
|
||||
|
||||
const char* arphrd_to_name(int id);
|
||||
int arphrd_from_name(const char *name);
|
||||
const char* arphrd_to_name(int id) _const_;
|
||||
int arphrd_from_name(const char *name) _pure_;
|
||||
|
||||
size_t arphrd_to_hw_addr_len(uint16_t arphrd);
|
||||
size_t arphrd_to_hw_addr_len(uint16_t arphrd) _const_;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include "forward.h"
|
||||
|
||||
const char* errno_to_name(int id);
|
||||
const char* errno_to_name(int id) _const_;
|
||||
int errno_from_name(const char *name) _pure_;
|
||||
|
||||
static inline bool errno_is_valid(int n) {
|
||||
|
||||
+23
-23
@@ -16,15 +16,15 @@ struct in_addr_data {
|
||||
union in_addr_union address;
|
||||
};
|
||||
|
||||
bool in4_addr_is_null(const struct in_addr *a);
|
||||
bool in4_addr_is_null(const struct in_addr *a) _pure_;
|
||||
static inline bool in4_addr_is_set(const struct in_addr *a) {
|
||||
return !in4_addr_is_null(a);
|
||||
}
|
||||
bool in6_addr_is_null(const struct in6_addr *a);
|
||||
bool in6_addr_is_null(const struct in6_addr *a) _pure_;
|
||||
static inline bool in6_addr_is_set(const struct in6_addr *a) {
|
||||
return !in6_addr_is_null(a);
|
||||
}
|
||||
int in_addr_is_null(int family, const union in_addr_union *u);
|
||||
int in_addr_is_null(int family, const union in_addr_union *u) _pure_;
|
||||
static inline bool in_addr_is_set(int family, const union in_addr_union *u) {
|
||||
return in_addr_is_null(family, u) == 0;
|
||||
}
|
||||
@@ -36,43 +36,43 @@ static inline bool in_addr_data_is_set(const struct in_addr_data *a) {
|
||||
return in_addr_data_is_null(a);
|
||||
}
|
||||
|
||||
bool in4_addr_is_multicast(const struct in_addr *a);
|
||||
bool in6_addr_is_multicast(const struct in6_addr *a);
|
||||
int in_addr_is_multicast(int family, const union in_addr_union *u);
|
||||
bool in4_addr_is_multicast(const struct in_addr *a) _pure_;
|
||||
bool in6_addr_is_multicast(const struct in6_addr *a) _pure_;
|
||||
int in_addr_is_multicast(int family, const union in_addr_union *u) _pure_;
|
||||
|
||||
bool in4_addr_is_link_local(const struct in_addr *a);
|
||||
bool in4_addr_is_link_local_dynamic(const struct in_addr *a);
|
||||
bool in6_addr_is_link_local(const struct in6_addr *a);
|
||||
int in_addr_is_link_local(int family, const union in_addr_union *u);
|
||||
bool in6_addr_is_link_local_all_nodes(const struct in6_addr *a);
|
||||
bool in4_addr_is_link_local(const struct in_addr *a) _pure_;
|
||||
bool in4_addr_is_link_local_dynamic(const struct in_addr *a) _pure_;
|
||||
bool in6_addr_is_link_local(const struct in6_addr *a) _pure_;
|
||||
int in_addr_is_link_local(int family, const union in_addr_union *u) _pure_;
|
||||
bool in6_addr_is_link_local_all_nodes(const struct in6_addr *a) _pure_;
|
||||
|
||||
bool in4_addr_is_localhost(const struct in_addr *a);
|
||||
int in_addr_is_localhost(int family, const union in_addr_union *u);
|
||||
int in_addr_is_localhost_one(int family, const union in_addr_union *u);
|
||||
bool in4_addr_is_localhost(const struct in_addr *a) _pure_;
|
||||
int in_addr_is_localhost(int family, const union in_addr_union *u) _pure_;
|
||||
int in_addr_is_localhost_one(int family, const union in_addr_union *u) _pure_;
|
||||
|
||||
bool in4_addr_is_local_multicast(const struct in_addr *a);
|
||||
bool in4_addr_is_non_local(const struct in_addr *a);
|
||||
bool in6_addr_is_ipv4_mapped_address(const struct in6_addr *a);
|
||||
bool in4_addr_is_local_multicast(const struct in_addr *a) _pure_;
|
||||
bool in4_addr_is_non_local(const struct in_addr *a) _pure_;
|
||||
bool in6_addr_is_ipv4_mapped_address(const struct in6_addr *a) _pure_;
|
||||
|
||||
bool in4_addr_equal(const struct in_addr *a, const struct in_addr *b);
|
||||
bool in6_addr_equal(const struct in6_addr *a, const struct in6_addr *b);
|
||||
int in_addr_equal(int family, const union in_addr_union *a, const union in_addr_union *b);
|
||||
bool in4_addr_equal(const struct in_addr *a, const struct in_addr *b) _pure_;
|
||||
bool in6_addr_equal(const struct in6_addr *a, const struct in6_addr *b) _pure_;
|
||||
int in_addr_equal(int family, const union in_addr_union *a, const union in_addr_union *b) _pure_;
|
||||
bool in4_addr_prefix_intersect(
|
||||
const struct in_addr *a,
|
||||
unsigned aprefixlen,
|
||||
const struct in_addr *b,
|
||||
unsigned bprefixlen);
|
||||
unsigned bprefixlen) _pure_;
|
||||
bool in6_addr_prefix_intersect(
|
||||
const struct in6_addr *a,
|
||||
unsigned aprefixlen,
|
||||
const struct in6_addr *b,
|
||||
unsigned bprefixlen);
|
||||
unsigned bprefixlen) _pure_;
|
||||
int in_addr_prefix_intersect(
|
||||
int family,
|
||||
const union in_addr_union *a,
|
||||
unsigned aprefixlen,
|
||||
const union in_addr_union *b,
|
||||
unsigned bprefixlen);
|
||||
unsigned bprefixlen) _pure_;
|
||||
int in_addr_prefix_next(int family, union in_addr_union *u, unsigned prefixlen);
|
||||
int in_addr_prefix_nth(int family, union in_addr_union *u, unsigned prefixlen, uint64_t nth);
|
||||
int in_addr_random_prefix(int family, union in_addr_union *u, unsigned prefixlen_fixed_part, unsigned prefixlen);
|
||||
|
||||
@@ -158,14 +158,14 @@ int file_in_same_dir(const char *path, const char *filename, char **ret);
|
||||
|
||||
bool hidden_or_backup_file(const char *filename) _pure_;
|
||||
|
||||
bool is_device_path(const char *path);
|
||||
bool is_device_path(const char *path) _pure_;
|
||||
|
||||
bool valid_device_node_path(const char *path);
|
||||
bool valid_device_allow_pattern(const char *path);
|
||||
bool valid_device_node_path(const char *path) _pure_;
|
||||
bool valid_device_allow_pattern(const char *path) _pure_;
|
||||
|
||||
bool dot_or_dot_dot(const char *path);
|
||||
bool dot_or_dot_dot(const char *path) _pure_;
|
||||
|
||||
bool path_implies_directory(const char *path);
|
||||
bool path_implies_directory(const char *path) _pure_;
|
||||
|
||||
static inline const char* skip_dev_prefix(const char *p) {
|
||||
const char *e;
|
||||
@@ -177,7 +177,7 @@ static inline const char* skip_dev_prefix(const char *p) {
|
||||
return e ?: p;
|
||||
}
|
||||
|
||||
bool empty_or_root(const char *path);
|
||||
bool empty_or_root(const char *path) _pure_;
|
||||
const char* empty_to_root(const char *path) _pure_;
|
||||
|
||||
bool path_strv_contains(char * const *l, const char *path);
|
||||
|
||||
@@ -136,7 +136,7 @@ void valgrind_summary_hack(void);
|
||||
|
||||
int pid_compare_func(const pid_t *a, const pid_t *b);
|
||||
|
||||
bool nice_is_valid(int n);
|
||||
bool nice_is_valid(int n) _const_;
|
||||
|
||||
bool sched_policy_is_valid(int i) _const_;
|
||||
bool sched_priority_is_valid(int i) _const_;
|
||||
|
||||
+1
-1
@@ -9,4 +9,4 @@ int sha256_fd(int fd, uint64_t max_size, uint8_t ret[static SHA256_DIGEST_SIZE])
|
||||
|
||||
int parse_sha256(const char *s, uint8_t res[static SHA256_DIGEST_SIZE]);
|
||||
|
||||
bool sha256_is_valid(const char *s);
|
||||
bool sha256_is_valid(const char *s) _pure_;
|
||||
|
||||
@@ -136,12 +136,12 @@ typedef enum {
|
||||
IFNAME_VALID_SPECIAL = 1 << 2, /* Allow the special names "all" and "default" */
|
||||
_IFNAME_VALID_ALL = IFNAME_VALID_ALTERNATIVE | IFNAME_VALID_NUMERIC | IFNAME_VALID_SPECIAL,
|
||||
} IfnameValidFlags;
|
||||
bool ifname_valid_char(char a);
|
||||
bool ifname_valid_full(const char *p, IfnameValidFlags flags);
|
||||
bool ifname_valid_char(char a) _const_;
|
||||
bool ifname_valid_full(const char *p, IfnameValidFlags flags) _pure_;
|
||||
static inline bool ifname_valid(const char *p) {
|
||||
return ifname_valid_full(p, 0);
|
||||
}
|
||||
bool address_label_valid(const char *p);
|
||||
bool address_label_valid(const char *p) _pure_;
|
||||
|
||||
int getpeercred(int fd, struct ucred *ucred);
|
||||
int getpeersec(int fd, char **ret);
|
||||
|
||||
@@ -85,15 +85,15 @@ bool statx_mount_same(const struct statx *a, const struct statx *b);
|
||||
|
||||
int xstatfsat(int dir_fd, const char *path, struct statfs *ret);
|
||||
|
||||
usec_t statx_timestamp_load(const struct statx_timestamp *ts);
|
||||
nsec_t statx_timestamp_load_nsec(const struct statx_timestamp *ts);
|
||||
usec_t statx_timestamp_load(const struct statx_timestamp *ts) _pure_;
|
||||
nsec_t statx_timestamp_load_nsec(const struct statx_timestamp *ts) _pure_;
|
||||
|
||||
void inode_hash_func(const struct stat *q, struct siphash *state);
|
||||
int inode_compare_func(const struct stat *a, const struct stat *b);
|
||||
extern const struct hash_ops inode_hash_ops;
|
||||
|
||||
const char* inode_type_to_string(mode_t m);
|
||||
mode_t inode_type_from_string(const char *s);
|
||||
const char* inode_type_to_string(mode_t m) _const_;
|
||||
mode_t inode_type_from_string(const char *s) _pure_;
|
||||
|
||||
/* Macros that check whether the stat/statx structures have been initialized already. For "struct stat" we
|
||||
* use a check for .st_dev being non-zero, since the kernel unconditionally fills that in, mapping the file
|
||||
|
||||
@@ -124,11 +124,11 @@ static inline char* skip_leading_chars(const char *s, const char *bad) {
|
||||
return (char*) s + strspn(s, bad);
|
||||
}
|
||||
|
||||
char ascii_tolower(char x);
|
||||
char ascii_tolower(char x) _const_;
|
||||
char* ascii_strlower(char *s);
|
||||
char* ascii_strlower_n(char *s, size_t n);
|
||||
|
||||
char ascii_toupper(char x);
|
||||
char ascii_toupper(char x) _const_;
|
||||
char* ascii_strupper(char *s);
|
||||
|
||||
int ascii_strcasecmp_n(const char *a, const char *b, size_t n);
|
||||
@@ -257,7 +257,7 @@ typedef enum MakeCStringMode {
|
||||
|
||||
int make_cstring(const char *s, size_t n, MakeCStringMode mode, char **ret);
|
||||
|
||||
size_t strspn_from_end(const char *str, const char *accept);
|
||||
size_t strspn_from_end(const char *str, const char *accept) _pure_;
|
||||
|
||||
char* strdupspn(const char *a, const char *accept);
|
||||
char* strdupcspn(const char *a, const char *reject);
|
||||
@@ -279,12 +279,11 @@ char* find_line_startswith(const char *haystack, const char *needle);
|
||||
char* find_line(const char *haystack, const char *needle);
|
||||
char* find_line_after(const char *haystack, const char *needle);
|
||||
|
||||
bool version_is_valid(const char *s);
|
||||
|
||||
bool version_is_valid_versionspec(const char *s);
|
||||
bool version_is_valid(const char *s) _pure_;
|
||||
bool version_is_valid_versionspec(const char *s) _pure_;
|
||||
|
||||
ssize_t strlevenshtein(const char *x, const char *y);
|
||||
|
||||
char* strrstr(const char *haystack, const char *needle);
|
||||
char* strrstr(const char *haystack, const char *needle) _pure_;
|
||||
|
||||
size_t str_common_prefix(const char *a, const char *b);
|
||||
size_t str_common_prefix(const char *a, const char *b) _pure_;
|
||||
|
||||
+3
-3
@@ -80,14 +80,14 @@ int strv_consume_prepend(char ***l, char *value);
|
||||
|
||||
char** strv_remove(char **l, const char *s);
|
||||
char** strv_uniq(char **l);
|
||||
bool strv_is_uniq(char * const *l);
|
||||
bool strv_is_uniq(char * const *l) _pure_;
|
||||
|
||||
int strv_compare(char * const *a, char * const *b);
|
||||
int strv_compare(char * const *a, char * const *b) _pure_;
|
||||
static inline bool strv_equal(char * const *a, char * const *b) {
|
||||
return strv_compare(a, b) == 0;
|
||||
}
|
||||
|
||||
bool strv_equal_ignore_order(char * const *a, char * const *b);
|
||||
bool strv_equal_ignore_order(char * const *a, char * const *b) _pure_;
|
||||
|
||||
char** strv_new_internal(const char *x, ...) _sentinel_;
|
||||
char** strv_new_ap(const char *x, va_list ap);
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#define MAP_UID_MIN ((uid_t) 60514)
|
||||
#define MAP_UID_MAX ((uid_t) 60577)
|
||||
|
||||
bool uid_is_valid(uid_t uid);
|
||||
bool uid_is_valid(uid_t uid) _const_;
|
||||
|
||||
static inline bool gid_is_valid(gid_t gid) {
|
||||
return uid_is_valid((uid_t) gid);
|
||||
@@ -37,8 +37,7 @@ char* getusername_malloc(void);
|
||||
const char* default_root_shell_at(int rfd);
|
||||
const char* default_root_shell(const char *root);
|
||||
|
||||
bool is_nologin_shell(const char *shell);
|
||||
|
||||
bool is_nologin_shell(const char *shell) _pure_;
|
||||
bool shell_is_placeholder(const char *shell) _pure_;
|
||||
|
||||
typedef enum UserCredsFlags {
|
||||
|
||||
+8
-8
@@ -6,7 +6,7 @@
|
||||
#define UTF8_REPLACEMENT_CHARACTER "\xef\xbf\xbd"
|
||||
#define UTF8_BYTE_ORDER_MARK "\xef\xbb\xbf"
|
||||
|
||||
bool unichar_is_valid(char32_t c);
|
||||
bool unichar_is_valid(char32_t c) _const_;
|
||||
|
||||
char* utf8_is_valid_n(const char *str, size_t len_bytes) _pure_;
|
||||
static inline char* utf8_is_valid(const char *str) {
|
||||
@@ -35,10 +35,10 @@ size_t utf16_encode_unichar(char16_t *out, char32_t c);
|
||||
char* utf16_to_utf8(const char16_t *s, size_t length /* bytes! */);
|
||||
char16_t *utf8_to_utf16(const char *s, size_t length);
|
||||
|
||||
size_t char16_strlen(const char16_t *s); /* returns the number of 16-bit words in the string (not bytes!) */
|
||||
size_t char16_strsize(const char16_t *s);
|
||||
size_t char16_strlen(const char16_t *s) _pure_; /* returns the number of 16-bit words in the string (not bytes!) */
|
||||
size_t char16_strsize(const char16_t *s) _pure_;
|
||||
|
||||
int utf8_encoded_valid_unichar(const char *str, size_t length);
|
||||
int utf8_encoded_valid_unichar(const char *str, size_t length) _pure_;
|
||||
int utf8_encoded_to_unichar(const char *str, char32_t *ret_unichar);
|
||||
|
||||
static inline bool utf16_is_surrogate(char16_t c) {
|
||||
@@ -53,8 +53,8 @@ static inline char32_t utf16_surrogate_pair_to_unichar(char16_t lead, char16_t t
|
||||
return ((((char32_t) lead - 0xd800U) << 10) + ((char32_t) trail - 0xdc00U) + 0x10000U);
|
||||
}
|
||||
|
||||
size_t utf8_n_codepoints(const char *str);
|
||||
int utf8_char_console_width(const char *str);
|
||||
size_t utf8_console_width(const char *str);
|
||||
size_t utf8_n_codepoints(const char *str) _pure_;
|
||||
int utf8_char_console_width(const char *str) _pure_;
|
||||
size_t utf8_console_width(const char *str) _pure_;
|
||||
|
||||
size_t utf8_last_length(const char *s, size_t n);
|
||||
size_t utf8_last_length(const char *s, size_t n) _pure_;
|
||||
|
||||
Reference in New Issue
Block a user