chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
hashmap: speed up hashmap allocations by introducing an allocation cache
[elogind.git]
/
src
/
util.c
diff --git
a/src/util.c
b/src/util.c
index b533b26dafc543a50abba861ef07c9f89c8cde9b..8d54049754c0495b2d4394483c9d2825fcc84f73 100644
(file)
--- a/
src/util.c
+++ b/
src/util.c
@@
-73,7
+73,7
@@
size_t page_size(void) {
static __thread size_t pgsz = 0;
long r;
static __thread size_t pgsz = 0;
long r;
- if (
pgsz
)
+ if (
_likely_(pgsz)
)
return pgsz;
assert_se((r = sysconf(_SC_PAGESIZE)) > 0);
return pgsz;
assert_se((r = sysconf(_SC_PAGESIZE)) > 0);
@@
-809,7
+809,7
@@
int parse_env_file(
const char *separator, ...) {
int r = 0;
const char *separator, ...) {
int r = 0;
- char *contents, *p;
+ char *contents
= NULL
, *p;
assert(fname);
assert(separator);
assert(fname);
assert(separator);
@@
-1266,8
+1266,6
@@
bool is_path(const char *p) {
}
char *path_make_absolute(const char *p, const char *prefix) {
}
char *path_make_absolute(const char *p, const char *prefix) {
- char *r;
-
assert(p);
/* Makes every item in the list an absolute path by prepending
assert(p);
/* Makes every item in the list an absolute path by prepending
@@
-1276,10
+1274,7
@@
char *path_make_absolute(const char *p, const char *prefix) {
if (path_is_absolute(p) || !prefix)
return strdup(p);
if (path_is_absolute(p) || !prefix)
return strdup(p);
- if (asprintf(&r, "%s/%s", prefix, p) < 0)
- return NULL;
-
- return r;
+ return join(prefix, "/", p, NULL);
}
char *path_make_absolute_cwd(const char *p) {
}
char *path_make_absolute_cwd(const char *p) {
@@
-3773,7
+3768,7
@@
int columns(void) {
static __thread int parsed_columns = 0;
const char *e;
static __thread int parsed_columns = 0;
const char *e;
- if (
parsed_columns > 0
)
+ if (
_likely_(parsed_columns > 0)
)
return parsed_columns;
if ((e = getenv("COLUMNS")))
return parsed_columns;
if ((e = getenv("COLUMNS")))
@@
-4369,7
+4364,7
@@
int detect_virtualization(const char **id) {
const char *_id;
int r;
const char *_id;
int r;
- if (
cached_id
) {
+ if (
_likely_(cached_id)
) {
if (cached_id == (const char*) -1)
return 0;
if (cached_id == (const char*) -1)
return 0;
@@
-5541,6
+5536,15
@@
char *join(const char *x, ...) {
return r;
}
return r;
}
+bool is_main_thread(void) {
+ static __thread int cached = 0;
+
+ if (_unlikely_(cached == 0))
+ cached = getpid() == gettid() ? 1 : -1;
+
+ return cached > 0;
+}
+
static const char *const ioprio_class_table[] = {
[IOPRIO_CLASS_NONE] = "none",
[IOPRIO_CLASS_RT] = "realtime",
static const char *const ioprio_class_table[] = {
[IOPRIO_CLASS_NONE] = "none",
[IOPRIO_CLASS_RT] = "realtime",