Browse Source

boost::regex optimization (building regexes can be somewhat resource demanding)

merge-requests/365/head
eidheim 10 years ago
parent
commit
df3eba9473
  1. 6
      src/cmake.cc
  2. 8
      src/source.cc
  3. 6
      src/source.h
  4. 6
      src/source_clang.cc

6
src/cmake.cc

@ -8,7 +8,7 @@
CMake::CMake(const boost::filesystem::path &path) {
const auto find_cmake_project=[this](const boost::filesystem::path &cmake_path) {
for(auto &line: filesystem::read_lines(cmake_path)) {
const boost::regex project_regex("^ *project *\\(.*$", boost::regex::icase);
const static boost::regex project_regex("^ *project *\\(.*$", boost::regex::icase);
boost::smatch sm;
if(boost::regex_match(line, sm, project_regex))
return true;
@ -207,7 +207,7 @@ void CMake::find_variables() {
if(end_line>start_line) {
auto line=file.substr(start_line, end_line-start_line);
boost::smatch sm;
const boost::regex set_regex("^ *set *\\( *([A-Za-z_][A-Za-z_0-9]*) +(.*)\\) *$", boost::regex::icase);
const static boost::regex set_regex("^ *set *\\( *([A-Za-z_][A-Za-z_0-9]*) +(.*)\\) *$", boost::regex::icase);
if(boost::regex_match(line, sm, set_regex)) {
auto data=sm[2].str();
while(data.size()>0 && data.back()==' ')
@ -216,7 +216,7 @@ void CMake::find_variables() {
variables[sm[1].str()]=data;
}
else {
const boost::regex project_regex("^ *project *\\( *([^ ]+).*\\) *$", boost::regex::icase);
const static boost::regex project_regex("^ *project *\\( *([^ ]+).*\\) *$", boost::regex::icase);
if(boost::regex_match(line, sm, project_regex)) {
auto data=sm[1].str();
parse_variable_parameters(data);

8
src/source.cc

@ -79,6 +79,10 @@ std::string Source::FixIt::string(Glib::RefPtr<Gtk::TextBuffer> buffer) {
//////////////
//// View ////
//////////////
const boost::regex Source::View::bracket_regex("^([ \\t]*).*\\{ *$");
const boost::regex Source::View::no_bracket_statement_regex("^([ \\t]*)(if|for|else if|while) *\\(.*[^;}] *$");
const boost::regex Source::View::no_bracket_no_para_statement_regex("^([ \\t]*)(else) *$");
AspellConfig* Source::View::spellcheck_config=NULL;
Source::View::View(const boost::filesystem::path &file_path, Glib::RefPtr<Gsv::Language> language): file_path(file_path), language(language) {
@ -271,10 +275,6 @@ Source::View::View(const boost::filesystem::path &file_path, Glib::RefPtr<Gsv::L
set_tooltip_and_dialog_events();
bracket_regex=boost::regex("^([ \\t]*).*\\{ *$");
no_bracket_statement_regex=boost::regex("^([ \\t]*)(if|for|else if|while) *\\(.*[^;}] *$");
no_bracket_no_para_statement_regex=boost::regex("^([ \\t]*)(else) *$");
if(language && (language->get_id()=="chdr" || language->get_id()=="cpphdr" || language->get_id()=="c" ||
language->get_id()=="cpp" || language->get_id()=="objc" || language->get_id()=="java" ||
language->get_id()=="js" || language->get_id()=="ts" || language->get_id()=="proto" ||

6
src/source.h

@ -138,9 +138,9 @@ namespace Source {
bool find_right_bracket_forward(Gtk::TextIter iter, Gtk::TextIter &found_iter);
bool find_left_bracket_backward(Gtk::TextIter iter, Gtk::TextIter &found_iter);
boost::regex bracket_regex;
boost::regex no_bracket_statement_regex;
boost::regex no_bracket_no_para_statement_regex;
const static boost::regex bracket_regex;
const static boost::regex no_bracket_statement_regex;
const static boost::regex no_bracket_no_para_statement_regex;
bool on_key_press_event(GdkEventKey* key) override;
bool on_key_press_event_basic(GdkEventKey* key);

6
src/source_clang.cc

@ -187,7 +187,7 @@ std::vector<std::string> Source::ClangViewParse::get_compilation_commands() {
}
}
auto clang_version_string=clang::to_string(clang_getClangVersion());
const boost::regex clang_version_regex("^[A-Za-z ]+([0-9.]+).*$");
const static boost::regex clang_version_regex("^[A-Za-z ]+([0-9.]+).*$");
boost::smatch sm;
if(boost::regex_match(clang_version_string, sm, clang_version_regex)) {
auto clang_version=sm[1].str();
@ -634,8 +634,8 @@ void Source::ClangViewAutocomplete::autocomplete_check() {
get_source_buffer()->iter_has_context_class(iter, "comment")))
return;
std::string line=" "+get_line_before();
const boost::regex in_specified_namespace("^(.*[a-zA-Z0-9_\\)\\]\\>])(->|\\.|::)([a-zA-Z0-9_]*)$");
const boost::regex within_namespace("^(.*)([^a-zA-Z0-9_]+)([a-zA-Z0-9_]{3,})$");
const static boost::regex in_specified_namespace("^(.*[a-zA-Z0-9_\\)\\]\\>])(->|\\.|::)([a-zA-Z0-9_]*)$");
const static boost::regex within_namespace("^(.*)([^a-zA-Z0-9_]+)([a-zA-Z0-9_]{3,})$");
boost::smatch sm;
if(boost::regex_match(line, sm, in_specified_namespace)) {
{

Loading…
Cancel
Save