Skip to content

Commit 4af9d7e

Browse files
author
Will
committed
watcher/linux/inotify: opt. common path of one event to avoid re-hashing potentially large path strings, and avoid null checks which have already been made by the caller
1 parent fec3ff2 commit 4af9d7e

2 files changed

Lines changed: 17 additions & 23 deletions

File tree

devel/include/detail/wtr/watcher/adapter/linux/inotify/watch.hpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,10 @@ inline auto parse_ev = [](
195195
using ev_et = enum ev::effect_type;
196196
auto pathof = [&](inotify_event const* const m)
197197
{ return known_pathof_wd_or_default(dm, m->wd) / m->name; };
198-
auto pt = in->mask & IN_ISDIR ? ev_pt::dir : ev_pt::file;
198+
auto in_path = pathof(in);
199+
auto pt = in->mask & IN_ISDIR ? ev_pt::dir
200+
: is_symlink(in_path) ? ev_pt::sym_link
201+
: ev_pt::file;
199202
auto et = in->mask & IN_CREATE ? ev_et::create
200203
: in->mask & IN_DELETE ? ev_et::destroy
201204
: in->mask & IN_MOVE ? ev_et::rename
@@ -205,15 +208,15 @@ inline auto parse_ev = [](
205208
{ return b && b->cookie && b->cookie == a->cookie && et == ev_et::rename; };
206209
auto isfromto = [](auto* a, auto* b) -> bool
207210
{ return (a->mask & IN_MOVED_FROM) && (b->mask & IN_MOVED_TO); };
208-
auto one = [&](auto* a, auto* next) -> parsed
209-
{ return {ev(pathof(a), et, pt), next}; };
211+
auto one = [&](auto* next) -> parsed
212+
{ return {ev(in_path, et, pt), next}; };
210213
auto assoc = [&](auto* a, auto* b) -> parsed
211214
{ return {ev(ev(pathof(a), et, pt), ev(pathof(b), et, pt)), peek(b, tail)}; };
212215
auto next = peek(in, tail);
213-
return ! isassoc(in, next) ? one(in, next)
216+
return ! isassoc(in, next) ? one(next)
214217
: isfromto(in, next) ? assoc(in, next)
215218
: isfromto(next, in) ? assoc(next, in)
216-
: (*ec = 1, one(in, next));
219+
: (*ec = 1, one(next));
217220
};
218221

219222
struct defer_dm_rm_wd {

include/wtr/watcher.hpp

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,14 +1478,10 @@ inline auto parse_ev = [](
14781478
using ev_et = enum ev::effect_type;
14791479
auto pathof = [&](inotify_event const* const m)
14801480
{ return known_pathof_wd_or_default(dm, m->wd) / m->name; };
1481-
auto calc_pt = [&](inotify_event const* const ev_ptr) -> ev_pt
1482-
{
1483-
// Return other type if pointer is null
1484-
if (! ev_ptr) return ev_pt::other;
1485-
return ev_ptr->mask & IN_ISDIR ? ev_pt::dir
1486-
: is_symlink(pathof(ev_ptr)) ? ev_pt::sym_link
1487-
: ev_pt::file;
1488-
};
1481+
auto in_path = pathof(in);
1482+
auto pt = in->mask & IN_ISDIR ? ev_pt::dir
1483+
: is_symlink(in_path) ? ev_pt::sym_link
1484+
: ev_pt::file;
14891485
auto et = in->mask & IN_CREATE ? ev_et::create
14901486
: in->mask & IN_DELETE ? ev_et::destroy
14911487
: in->mask & IN_MOVE ? ev_et::rename
@@ -1495,20 +1491,15 @@ inline auto parse_ev = [](
14951491
{ return b && b->cookie && b->cookie == a->cookie && et == ev_et::rename; };
14961492
auto isfromto = [](auto* a, auto* b) -> bool
14971493
{ return (a->mask & IN_MOVED_FROM) && (b->mask & IN_MOVED_TO); };
1498-
auto one = [&](auto* a, auto* next) -> parsed
1499-
{ return {ev(pathof(a), et, calc_pt(a)), next}; };
1494+
auto one = [&](auto* next) -> parsed
1495+
{ return {ev(in_path, et, pt), next}; };
15001496
auto assoc = [&](auto* a, auto* b) -> parsed
1501-
{
1502-
auto pt_b = calc_pt(b);
1503-
return {
1504-
ev(ev(pathof(a), et, pt_b), ev(pathof(b), et, pt_b)),
1505-
peek(b, tail)};
1506-
};
1497+
{ return {ev(ev(pathof(a), et, pt), ev(pathof(b), et, pt)), peek(b, tail)}; };
15071498
auto next = peek(in, tail);
1508-
return ! isassoc(in, next) ? one(in, next)
1499+
return ! isassoc(in, next) ? one(next)
15091500
: isfromto(in, next) ? assoc(in, next)
15101501
: isfromto(next, in) ? assoc(next, in)
1511-
: (*ec = 1, one(in, next));
1502+
: (*ec = 1, one(next));
15121503
};
15131504

15141505
struct defer_dm_rm_wd {

0 commit comments

Comments
 (0)