diff --git a/src/parse/FileContext.cpp b/src/parse/FileContext.cpp index 48f2425..0396ea3 100644 --- a/src/parse/FileContext.cpp +++ b/src/parse/FileContext.cpp @@ -2,8 +2,8 @@ namespace kc { -FileContext::FileContext(kc::FileEntry entry) -: file_entry(std::make_shared(entry)) +FileContext::FileContext(std::shared_ptr entry) +: file_entry(entry) { } @@ -33,7 +33,7 @@ void FileContext::parse() std::smatch image_match; while(std::regex_search(file_content, image_match, image_regex)) { - images.push_back(image_match.str()); + images.push_back(kc::Link(image_match.str())); file_content = image_match.suffix(); } diff --git a/src/parse/FileContext.hpp b/src/parse/FileContext.hpp index 2d553a7..c317a6b 100644 --- a/src/parse/FileContext.hpp +++ b/src/parse/FileContext.hpp @@ -13,7 +13,7 @@ namespace kc { class FileContext { public: - FileContext(kc::FileEntry entry); + FileContext(std::shared_ptr entry); std::shared_ptr file_entry; std::vector links; diff --git a/src/parse/FileContextCache.cpp b/src/parse/FileContextCache.cpp index b28cfa6..d41f7c2 100644 --- a/src/parse/FileContextCache.cpp +++ b/src/parse/FileContextCache.cpp @@ -1,20 +1,25 @@ #include "FileContextCache.hpp" + +#include +#include + #include "../fs/fs.hpp" #include "../logging.hpp" namespace kc { -void FileContextCache::load(std::string root_path) +void FileContextCache::load(const std::string root_path) { BOOST_LOG_TRIVIAL(trace) << "Beginning cache load"; auto entries = kc::walk_dir(root_path); + this->root_path.assign(root_path); for (auto entry : entries) { - if (entry.relative_path.extension() == ".md") + if (entry->relative_path.extension() == ".md") { - entry.load_content(); + entry->load_content(); } file_contexts.push_back(std::make_shared(entry)); @@ -26,8 +31,14 @@ void FileContextCache::load(std::string root_path) void FileContextCache::parse_all() { tag_map.clear(); - for (auto context: file_contexts) - { + +#if __APPLE__ + std::for_each(file_contexts.begin(), file_contexts.end(), [this](std::shared_ptr &context) +#else + std::for_each(std::execution::par_unseq, file_contexts.begin(), file_contexts.end(), [this](std::shared_ptr &context) +#endif + + { if (context->file_entry->relative_path.extension() == ".md") { context->parse(); @@ -40,7 +51,7 @@ void FileContextCache::parse_all() } } } - } + }); } void FileContextCache::clear() @@ -49,14 +60,19 @@ void FileContextCache::clear() file_contexts.shrink_to_fit(); } -size_t FileContextCache::size() +size_t FileContextCache::size() const { return file_contexts.size(); } -std::vector> FileContextCache::get() +std::vector> FileContextCache::get() const { return file_contexts; } +std::string FileContextCache::get_root_path() const +{ + return root_path; +} + } \ No newline at end of file diff --git a/src/parse/FileContextCache.hpp b/src/parse/FileContextCache.hpp index 8229c0c..b308f53 100644 --- a/src/parse/FileContextCache.hpp +++ b/src/parse/FileContextCache.hpp @@ -12,14 +12,16 @@ class FileContextCache { public: void load(std::string root_path); void clear(); - size_t size(); - std::vector> get(); + size_t size() const; + std::vector> get() const; void parse_all(); + std::string get_root_path() const; std::unordered_map>> tag_map; private: std::vector> file_contexts; + std::string root_path; }; } \ No newline at end of file