Browse Source

Added std::regex::optimize to std::regex object constructions

pipelines/235045657
eidheim 5 years ago
parent
commit
2be7e1c943
  1. 2
      src/cmake.cpp
  2. 4
      src/compile_commands.cpp
  3. 2
      src/meson.cpp
  4. 4
      src/source.cpp
  5. 5
      src/source_clang.cpp
  6. 3
      src/source_language_protocol.cpp
  7. 3
      src/terminal.cpp
  8. 4
      src/tooltips.cpp
  9. 2
      src/usages_clang.cpp

2
src/cmake.cpp

@ -15,7 +15,7 @@ CMake::CMake(const boost::filesystem::path &path) {
if(input) { if(input) {
std::string line; std::string line;
while(std::getline(input, 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; std::smatch sm;
if(std::regex_match(line, sm, project_regex)) if(std::regex_match(line, sm, project_regex))
return true; return true;

4
src/compile_commands.cpp

@ -175,7 +175,7 @@ std::vector<std::string> CompileCommands::get_arguments(const boost::filesystem:
arguments.emplace_back("-F" + path); arguments.emplace_back("-F" + path);
#ifdef _WIN32 #ifdef _WIN32
auto clang_version_string = clangmm::to_string(clang_getClangVersion()); 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; std::smatch sm;
if(std::regex_match(clang_version_string, sm, clang_version_regex)) { if(std::regex_match(clang_version_string, sm, clang_version_regex)) {
auto clang_version = sm[1].str(); auto clang_version = sm[1].str();
@ -187,7 +187,7 @@ std::vector<std::string> CompileCommands::get_arguments(const boost::filesystem:
} }
else { else {
auto clang_version_string = clangmm::to_string(clang_getClangVersion()); 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; std::smatch sm;
if(std::regex_match(clang_version_string, sm, clang_version_regex)) { if(std::regex_match(clang_version_string, sm, clang_version_regex)) {
auto clang_version = sm[1].str(); auto clang_version = sm[1].str();

2
src/meson.cpp

@ -14,7 +14,7 @@ Meson::Meson(const boost::filesystem::path &path) {
if(input) { if(input) {
std::string line; std::string line;
while(std::getline(input, 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; std::smatch sm;
if(std::regex_match(line, sm, project_regex)) if(std::regex_match(line, sm, project_regex))
return true; return true;

4
src/source.cpp

@ -784,7 +784,7 @@ void Source::View::setup_format_style(bool is_generic_view) {
} }
} }
else if(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::string line;
std::getline(stderr_stream, line); std::getline(stderr_stream, line);
std::smatch sm; 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) { bool Source::View::on_key_press_event_bracket_language(GdkEventKey *key) {
const static std::regex no_bracket_statement_regex("^[ \t]*(if( +constexpr)?|for|while) *\\(.*[^;}{] *$|" const static std::regex no_bracket_statement_regex("^[ \t]*(if( +constexpr)?|for|while) *\\(.*[^;}{] *$|"
"^[ \t]*[}]? *else if( +constexpr)? *\\(.*[^;}{] *$|" "^[ \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(); auto iter = get_buffer()->get_insert()->get_iter();

5
src/source_clang.cpp

@ -15,7 +15,7 @@
#include "usages_clang.hpp" #include "usages_clang.hpp"
#include "utility.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<Gsv::Language> &language) Source::ClangViewParse::ClangViewParse(const boost::filesystem::path &file_path, const Glib::RefPtr<Gsv::Language> &language)
: BaseView(file_path, language), Source::View(file_path, 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(); 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 -> 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-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; std::smatch sm;
if(std::regex_match(line, sm, regex)) { if(std::regex_match(line, sm, regex)) {
{ {

3
src/source_language_protocol.cpp

@ -1451,7 +1451,8 @@ void Source::LanguageProtocolView::setup_autocomplete() {
auto line = ' ' + get_line_before(); 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_]*)$|" // . 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-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; std::smatch sm;
if(std::regex_match(line, sm, regex)) { if(std::regex_match(line, sm, regex)) {
{ {

3
src/terminal.cpp

@ -226,7 +226,8 @@ boost::optional<Terminal::Link> Terminal::find_link(const std::string &line, siz
"^[^:]*: ([A-Z]:)?([^:]+):([0-9]+): .* Assertion .* failed\\.$|" // gcc assert() "^[^:]*: ([A-Z]:)?([^:]+):([0-9]+): .* Assertion .* failed\\.$|" // gcc assert()
"^ERROR:([A-Z]:)?([^:]+):([0-9]+):.*$|" // g_assert (glib.h) "^ERROR:([A-Z]:)?([^:]+):([0-9]+):.*$|" // g_assert (glib.h)
"^([A-Z]:)?([\\/][^:]+):([0-9]+)$|" // Node.js "^([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; std::smatch sm;
if(std::regex_match(line.cbegin() + pos, if(std::regex_match(line.cbegin() + pos,
line.cbegin() + (length == std::string::npos ? line.size() : std::min(pos + length, line.size())), line.cbegin() + (length == std::string::npos ? line.size() : std::min(pos + length, line.size())),

4
src/tooltips.cpp

@ -154,7 +154,7 @@ void Tooltip::show(bool disregard_drawn, const std::function<void()> &on_motion)
return true; return true;
} }
static std::regex regex("^([^:]+):([^:]+):([^:]+)$"); const static std::regex regex("^([^:]+):([^:]+):([^:]+)$", std::regex::optimize);
std::smatch sm; std::smatch sm;
if(std::regex_match(link, sm, regex)) { if(std::regex_match(link, sm, regex)) {
auto path = boost::filesystem::path(sm[1].str()); 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) { 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::smatch sm;
std::sregex_iterator it(text.begin(), text.end(), http_regex); std::sregex_iterator it(text.begin(), text.end(), http_regex);
std::sregex_iterator end; std::sregex_iterator end;

2
src/usages_clang.cpp

@ -578,7 +578,7 @@ std::pair<std::map<boost::filesystem::path, Usages::Clang::PathSet>, Usages::Cla
std::map<boost::filesystem::path, PathSet> paths_includes; std::map<boost::filesystem::path, PathSet> paths_includes;
PathSet paths_with_spelling; 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) { auto is_spelling_char = [](char chr) {
return (chr >= 'a' && chr <= 'z') || (chr >= 'A' && chr <= 'Z') || (chr >= '0' && chr <= '9') || chr == '_'; return (chr >= 'a' && chr <= 'z') || (chr >= 'A' && chr <= 'Z') || (chr >= '0' && chr <= '9') || chr == '_';

Loading…
Cancel
Save