From d66edc824dfdc265bf53e3173152589615ad77ec Mon Sep 17 00:00:00 2001 From: eidheim Date: Mon, 9 Nov 2015 09:11:46 +0100 Subject: [PATCH] Faster clang processing on open file, adds a slight delay first time the next reparse is performed. This is more clean with respect to using precompiled header files in the future. --- src/source_clang.cc | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/src/source_clang.cc b/src/source_clang.cc index ebad9e6..fdaef3d 100644 --- a/src/source_clang.cc +++ b/src/source_clang.cc @@ -113,24 +113,6 @@ void Source::ClangViewParse::init_parse() { parse_thread_mapped=false; parse_thread_stop=false; - auto buffer_map=get_buffer_map(); - //Remove includes for first parse for initial syntax highlighting - auto& str=buffer_map[file_path.string()]; - std::size_t pos=0; - while((pos=str.find("#include", pos))!=std::string::npos) { - auto start_pos=pos; - pos=str.find('\n', pos+8); - if(pos==std::string::npos) - break; - if(start_pos==0 || str[start_pos-1]=='\n') { - str.replace(start_pos, pos-start_pos, pos-start_pos, ' '); - } - pos++; - } - clang_tu = std::unique_ptr(new clang::TranslationUnit(clang_index, file_path.string(), get_compilation_commands(), buffer_map)); - clang_tokens=clang_tu->get_tokens(0, buffer_map.find(file_path.string())->second.size()-1); - update_syntax(); - set_status("parsing..."); if(parse_thread.joinable()) parse_thread.join(); @@ -145,7 +127,11 @@ void Source::ClangViewParse::init_parse() { parse_start(); } else if (parse_thread_mapped && parsing_mutex.try_lock() && parse_thread_buffer_map_mutex.try_lock()) { - int status=clang_tu->ReparseTranslationUnit(parse_thread_buffer_map); + int status=0; + if(!clang_tu) + clang_tu = std::unique_ptr(new clang::TranslationUnit(clang_index, file_path.string(), get_compilation_commands(), parse_thread_buffer_map)); + else + status=clang_tu->ReparseTranslationUnit(parse_thread_buffer_map); if(status==0) clang_tokens=clang_tu->get_tokens(0, parse_thread_buffer_map.find(file_path.string())->second.size()-1); else