From 2be7e1c94395c20d0479e642b9c80b8e61512fb5 Mon Sep 17 00:00:00 2001 From: eidheim Date: Tue, 7 Jul 2020 11:40:49 +0200 Subject: [PATCH] Added std::regex::optimize to std::regex object constructions --- src/cmake.cpp | 2 +- src/compile_commands.cpp | 4 ++-- src/meson.cpp | 2 +- src/source.cpp | 4 ++-- src/source_clang.cpp | 5 +++-- src/source_language_protocol.cpp | 3 ++- src/terminal.cpp | 3 ++- src/tooltips.cpp | 4 ++-- src/usages_clang.cpp | 2 +- 9 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/cmake.cpp b/src/cmake.cpp index 04863e8..ad8a420 100644 --- a/src/cmake.cpp +++ b/src/cmake.cpp @@ -15,7 +15,7 @@ CMake::CMake(const boost::filesystem::path &path) { if(input) { std::string line; while(std::getline(input, line)) { - const static std::regex project_regex("^ *project *\\(.*$", std::regex::icase); + const static std::regex project_regex("^ *project *\\(.*$", std::regex::icase | std::regex::optimize); std::smatch sm; if(std::regex_match(line, sm, project_regex)) return true; diff --git a/src/compile_commands.cpp b/src/compile_commands.cpp index c666043..e5c1198 100644 --- a/src/compile_commands.cpp +++ b/src/compile_commands.cpp @@ -175,7 +175,7 @@ std::vector CompileCommands::get_arguments(const boost::filesystem: arguments.emplace_back("-F" + path); #ifdef _WIN32 auto clang_version_string = clangmm::to_string(clang_getClangVersion()); - const static std::regex clang_version_regex(R"(^[A-Za-z ]+([0-9.]+).*$)"); + const static std::regex clang_version_regex(R"(^[A-Za-z ]+([0-9.]+).*$)", std::regex::optimize); std::smatch sm; if(std::regex_match(clang_version_string, sm, clang_version_regex)) { auto clang_version = sm[1].str(); @@ -187,7 +187,7 @@ std::vector CompileCommands::get_arguments(const boost::filesystem: } else { auto clang_version_string = clangmm::to_string(clang_getClangVersion()); - const static std::regex clang_version_regex(R"(^[A-Za-z ]+([0-9.]+).*$)"); + const static std::regex clang_version_regex(R"(^[A-Za-z ]+([0-9.]+).*$)", std::regex::optimize); std::smatch sm; if(std::regex_match(clang_version_string, sm, clang_version_regex)) { auto clang_version = sm[1].str(); diff --git a/src/meson.cpp b/src/meson.cpp index 33c7e0e..23bbe05 100644 --- a/src/meson.cpp +++ b/src/meson.cpp @@ -14,7 +14,7 @@ Meson::Meson(const boost::filesystem::path &path) { if(input) { std::string line; while(std::getline(input, line)) { - const static std::regex project_regex("^ *project *\\(.*", std::regex::icase); + const static std::regex project_regex("^ *project *\\(.*", std::regex::icase | std::regex::optimize); std::smatch sm; if(std::regex_match(line, sm, project_regex)) return true; diff --git a/src/source.cpp b/src/source.cpp index 1f2ccb6..944774b 100644 --- a/src/source.cpp +++ b/src/source.cpp @@ -784,7 +784,7 @@ void Source::View::setup_format_style(bool is_generic_view) { } } else if(is_generic_view) { - static std::regex regex(R"(^\[error\] [^:]*: (.*) \(([0-9]*):([0-9]*)\)$)"); + const static std::regex regex(R"(^\[error\] [^:]*: (.*) \(([0-9]*):([0-9]*)\)$)", std::regex::optimize); std::string line; std::getline(stderr_stream, line); std::smatch sm; @@ -2265,7 +2265,7 @@ bool Source::View::on_key_press_event_basic(GdkEventKey *key) { bool Source::View::on_key_press_event_bracket_language(GdkEventKey *key) { const static std::regex no_bracket_statement_regex("^[ \t]*(if( +constexpr)?|for|while) *\\(.*[^;}{] *$|" "^[ \t]*[}]? *else if( +constexpr)? *\\(.*[^;}{] *$|" - "^[ \t]*[}]? *else *$", std::regex::extended); + "^[ \t]*[}]? *else *$", std::regex::extended | std::regex::optimize); auto iter = get_buffer()->get_insert()->get_iter(); diff --git a/src/source_clang.cpp b/src/source_clang.cpp index ff6e384..6d2edf3 100644 --- a/src/source_clang.cpp +++ b/src/source_clang.cpp @@ -15,7 +15,7 @@ #include "usages_clang.hpp" #include "utility.hpp" -const std::regex include_regex(R"(^[ \t]*#[ \t]*include[ \t]*[<"]([^<>"]+)[>"].*$)"); +const std::regex include_regex(R"(^[ \t]*#[ \t]*include[ \t]*[<"]([^<>"]+)[>"].*$)", std::regex::optimize); Source::ClangViewParse::ClangViewParse(const boost::filesystem::path &file_path, const Glib::RefPtr &language) : BaseView(file_path, language), Source::View(file_path, language) { @@ -762,7 +762,8 @@ Source::ClangViewAutocomplete::ClangViewAutocomplete(const boost::filesystem::pa auto line = ' ' + get_line_before(); const static std::regex regex("^.*([a-zA-Z_\\)\\]\\>]|[^a-zA-Z0-9_][a-zA-Z_][a-zA-Z0-9_]*)(\\.|->)([a-zA-Z0-9_]*)$|" // . or -> "^.*(::)([a-zA-Z0-9_]*)$|" // :: - "^.*[^a-zA-Z0-9_]([a-zA-Z_][a-zA-Z0-9_]{2,})$"); // part of symbol + "^.*[^a-zA-Z0-9_]([a-zA-Z_][a-zA-Z0-9_]{2,})$", // part of symbol + std::regex::optimize); std::smatch sm; if(std::regex_match(line, sm, regex)) { { diff --git a/src/source_language_protocol.cpp b/src/source_language_protocol.cpp index a90fd3c..b2c83dd 100644 --- a/src/source_language_protocol.cpp +++ b/src/source_language_protocol.cpp @@ -1451,7 +1451,8 @@ void Source::LanguageProtocolView::setup_autocomplete() { auto line = ' ' + get_line_before(); const static std::regex regex("^.*([a-zA-Z_\\)\\]\\>\"']|[^a-zA-Z0-9_][a-zA-Z_][a-zA-Z0-9_]*\\?{0,1})(\\.)([a-zA-Z0-9_]*)$|" // . "^.*(::)([a-zA-Z0-9_]*)$|" // :: - "^.*[^a-zA-Z0-9_]([a-zA-Z_][a-zA-Z0-9_]{2,})$"); // part of symbol + "^.*[^a-zA-Z0-9_]([a-zA-Z_][a-zA-Z0-9_]{2,})$", // part of symbol + std::regex::optimize); std::smatch sm; if(std::regex_match(line, sm, regex)) { { diff --git a/src/terminal.cpp b/src/terminal.cpp index e33eeca..41b7d43 100644 --- a/src/terminal.cpp +++ b/src/terminal.cpp @@ -226,7 +226,8 @@ boost::optional Terminal::find_link(const std::string &line, siz "^[^:]*: ([A-Z]:)?([^:]+):([0-9]+): .* Assertion .* failed\\.$|" // gcc assert() "^ERROR:([A-Z]:)?([^:]+):([0-9]+):.*$|" // g_assert (glib.h) "^([A-Z]:)?([\\/][^:]+):([0-9]+)$|" // Node.js - "^ File \"([A-Z]:)?([^\"]+)\", line ([0-9]+), in .*$"); // Python + "^ File \"([A-Z]:)?([^\"]+)\", line ([0-9]+), in .*$", // Python + std::regex::optimize); std::smatch sm; if(std::regex_match(line.cbegin() + pos, line.cbegin() + (length == std::string::npos ? line.size() : std::min(pos + length, line.size())), diff --git a/src/tooltips.cpp b/src/tooltips.cpp index 7ef3e91..90e911a 100644 --- a/src/tooltips.cpp +++ b/src/tooltips.cpp @@ -154,7 +154,7 @@ void Tooltip::show(bool disregard_drawn, const std::function &on_motion) return true; } - static std::regex regex("^([^:]+):([^:]+):([^:]+)$"); + const static std::regex regex("^([^:]+):([^:]+):([^:]+)$", std::regex::optimize); std::smatch sm; if(std::regex_match(link, sm, regex)) { auto path = boost::filesystem::path(sm[1].str()); @@ -404,7 +404,7 @@ void Tooltip::create_tags() { } void Tooltip::insert_with_links_tagged(const std::string &text) { - static std::regex http_regex("(https?://[a-zA-Z0-9\\-._~:/?#\\[\\]@!$&'()*+,;=]+[a-zA-Z0-9\\-_~/@$*+;=])"); + const static std::regex http_regex("(https?://[a-zA-Z0-9\\-._~:/?#\\[\\]@!$&'()*+,;=]+[a-zA-Z0-9\\-_~/@$*+;=])", std::regex::optimize); std::smatch sm; std::sregex_iterator it(text.begin(), text.end(), http_regex); std::sregex_iterator end; diff --git a/src/usages_clang.cpp b/src/usages_clang.cpp index 2398ab7..4766d4e 100644 --- a/src/usages_clang.cpp +++ b/src/usages_clang.cpp @@ -578,7 +578,7 @@ std::pair, Usages::Cla std::map paths_includes; PathSet paths_with_spelling; - const static std::regex include_regex(R"R(^#[ \t]*include[ \t]*"([^"]+)".*$)R"); + const static std::regex include_regex(R"R(^#[ \t]*include[ \t]*"([^"]+)".*$)R", std::regex::optimize); auto is_spelling_char = [](char chr) { return (chr >= 'a' && chr <= 'z') || (chr >= 'A' && chr <= 'Z') || (chr >= '0' && chr <= '9') || chr == '_';