From 3e6110dec6f4cb004b8594b9b798a9db5b08fe7a Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Wed, 7 Dec 2016 01:22:53 +0300 Subject: Add path::current(), path::parent() --- butl/filesystem.cxx | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'butl/filesystem.cxx') diff --git a/butl/filesystem.cxx b/butl/filesystem.cxx index 424e361..0643938 100644 --- a/butl/filesystem.cxx +++ b/butl/filesystem.cxx @@ -531,14 +531,17 @@ namespace butl errno = 0; if (struct dirent* de = readdir (h_)) { - const char* n (de->d_name); + // We can accept some overhead for '.' and '..' (relying on short + // string optimization) in favor of a more compact code. + // + path p (de->d_name); // Skip '.' and '..'. // - if (n[0] == '.' && (n[1] == '\0' || (n[1] == '.' && n[2] == '\0'))) + if (p.current () || p.parent ()) continue; - e_.p_ = path (n); + e_.p_ = move (p); e_.t_ = d_type (de, nullptr); e_.lt_ = entry_type::unknown; } @@ -665,14 +668,17 @@ namespace butl if (r) { - const char* n (fi.name); + // We can accept some overhead for '.' and '..' (relying on short + // string optimization) in favor of a more compact code. + // + path p (fi.name); // Skip '.' and '..'. // - if (n[0] == '.' && (n[1] == '\0' || (n[1] == '.' && n[2] == '\0'))) + if (p.current () || p.parent ()) continue; - e_.p_ = path (n); + e_.p_ = move (p); // We do not support symlinks at the moment. // -- cgit v1.1