From 7ffb2421a232d154f21b1ab5b2cd2e386bbb5b7a Mon Sep 17 00:00:00 2001 From: Shaun Ruffell Date: Thu, 8 Jul 2021 09:39:45 -0500 Subject: [PATCH] AtomicFile: Minor cleanups 1) Remove AtomicFile::impl::find and use std::find_if directly. 2) Remove static functions that take a string for path. Allow the compiler to construct the Path object as necessary. Signed-off-by: Shaun Ruffell --- src/AtomicFile.cpp | 45 +++++++++------------------------------------ src/AtomicFile.h | 3 --- 2 files changed, 9 insertions(+), 39 deletions(-) diff --git a/src/AtomicFile.cpp b/src/AtomicFile.cpp index d1eae798..81e107f3 100644 --- a/src/AtomicFile.cpp +++ b/src/AtomicFile.cpp @@ -279,27 +279,19 @@ void AtomicFile::impl::finalize () } } -//////////////////////////////////////////////////////////////////////////////// -AtomicFile::impl::iterator AtomicFile::impl::find (const Path& path) -{ - auto end = impl::atomic_files.end (); - auto cmp = [&path](const atomic_files_t::value_type& p) - { - return p->real_file == path; - }; - auto it = std::find_if(impl::atomic_files.begin (), end, cmp); - return (it == end) ? end : it; -} - - //////////////////////////////////////////////////////////////////////////////// AtomicFile::AtomicFile (const Path& path) { - auto it = impl::find (path); + auto end = impl::atomic_files.end (); + auto it = std::find_if (impl::atomic_files.begin (), end, + [&path] (const impl::value_type& p) + { + return p->real_file == path; + }); - if (it == impl::atomic_files.end ()) + if (it == end) { - pimpl = std::make_shared (path._data); + pimpl = std::make_shared (path); impl::atomic_files.push_back (pimpl); } else @@ -400,18 +392,6 @@ void AtomicFile::write_raw (const std::string& content) pimpl->write_raw (content); } -//////////////////////////////////////////////////////////////////////////////// -void AtomicFile::append (const std::string& path, const std::string& data) -{ - return AtomicFile(path).append (data); -} - -//////////////////////////////////////////////////////////////////////////////// -void AtomicFile::write (const std::string& path, const std::string& data) -{ - AtomicFile::write (Path (path), data); -} - //////////////////////////////////////////////////////////////////////////////// void AtomicFile::write (const Path& path, const std::string& data) { @@ -434,14 +414,7 @@ void AtomicFile::write (const Path& path, const std::vector & lines //////////////////////////////////////////////////////////////////////////////// void AtomicFile::read (const Path& path, std::string& content) { - AtomicFile file (path); - file.read (content); -} - -//////////////////////////////////////////////////////////////////////////////// -void AtomicFile::read (const std::string& path, std::string& content) -{ - AtomicFile::read (Path (path), content); + AtomicFile (path).read (content); } void AtomicFile::read (const Path& path, std::vector & lines) diff --git a/src/AtomicFile.h b/src/AtomicFile.h index 39c06af2..53a4deea 100644 --- a/src/AtomicFile.h +++ b/src/AtomicFile.h @@ -56,14 +56,11 @@ public: void append (const std::string& content); void write_raw (const std::string& content); - static void append (const std::string& path, const std::string& data); static void append (const Path& path, const std::string& data); - static void write (const std::string& path, const std::string& data); static void write (const Path& path, const std::string& data); static void write (const Path& path, const std::vector & lines); - static void read (const std::string& path, std::string& content); static void read (const Path& path, std::string& content); static void read (const Path& path, std::vector & lines);