Browse Source

Removed unnecessary mutex from GenericView

pipelines/353213535
eidheim 4 years ago
parent
commit
0a28c1822f
  1. 9
      src/source_generic.cpp
  2. 6
      src/source_generic.hpp

9
src/source_generic.cpp

@ -87,7 +87,6 @@ std::vector<std::pair<Gtk::TextIter, Gtk::TextIter>> Source::GenericView::get_wo
void Source::GenericView::setup_buffer_words() { void Source::GenericView::setup_buffer_words() {
{ {
auto words = get_words(get_buffer()->begin(), get_buffer()->end()); auto words = get_words(get_buffer()->begin(), get_buffer()->end());
LockGuard lock(buffer_words_mutex);
for(auto &word : words) { for(auto &word : words) {
auto result = buffer_words.emplace(get_buffer()->get_text(word.first, word.second), 1); auto result = buffer_words.emplace(get_buffer()->get_text(word.first, word.second), 1);
if(!result.second) if(!result.second)
@ -105,7 +104,6 @@ void Source::GenericView::setup_buffer_words() {
if(is_token_char(*iter)) { if(is_token_char(*iter)) {
auto word = get_token_iters(iter); auto word = get_token_iters(iter);
if(word.second.get_offset() - word.first.get_offset() >= 3) { if(word.second.get_offset() - word.first.get_offset() >= 3) {
LockGuard lock(buffer_words_mutex);
auto it = buffer_words.find(get_buffer()->get_text(word.first, word.second)); auto it = buffer_words.find(get_buffer()->get_text(word.first, word.second));
if(it != buffer_words.end()) { if(it != buffer_words.end()) {
if(it->second > 1) if(it->second > 1)
@ -128,7 +126,6 @@ void Source::GenericView::setup_buffer_words() {
end.forward_char(); end.forward_char();
auto words = get_words(start, end); auto words = get_words(start, end);
LockGuard lock(buffer_words_mutex);
for(auto &word : words) { for(auto &word : words) {
auto result = buffer_words.emplace(get_buffer()->get_text(word.first, word.second), 1); auto result = buffer_words.emplace(get_buffer()->get_text(word.first, word.second), 1);
if(!result.second) if(!result.second)
@ -145,7 +142,6 @@ void Source::GenericView::setup_buffer_words() {
start.backward_char(); start.backward_char();
end.forward_char(); end.forward_char();
auto words = get_words(start, end); auto words = get_words(start, end);
LockGuard lock(buffer_words_mutex);
for(auto &word : words) { for(auto &word : words) {
auto it = buffer_words.find(get_buffer()->get_text(word.first, word.second)); auto it = buffer_words.find(get_buffer()->get_text(word.first, word.second));
if(it != buffer_words.end()) { if(it != buffer_words.end()) {
@ -166,7 +162,6 @@ void Source::GenericView::setup_buffer_words() {
if(is_token_char(*start)) { if(is_token_char(*start)) {
auto word = get_token_iters(start); auto word = get_token_iters(start);
if(word.second.get_offset() - word.first.get_offset() >= 3) { if(word.second.get_offset() - word.first.get_offset() >= 3) {
LockGuard lock(buffer_words_mutex);
auto result = buffer_words.emplace(get_buffer()->get_text(word.first, word.second), 1); auto result = buffer_words.emplace(get_buffer()->get_text(word.first, word.second), 1);
if(!result.second) if(!result.second)
++(result.first->second); ++(result.first->second);
@ -194,8 +189,7 @@ void Source::GenericView::setup_autocomplete() {
prefix_start.forward_char(); prefix_start.forward_char();
if((count >= 3 && !(*prefix_start >= '0' && *prefix_start <= '9')) || !interactive_completion) { if((count >= 3 && !(*prefix_start >= '0' && *prefix_start <= '9')) || !interactive_completion) {
LockGuard lock1(autocomplete.prefix_mutex); LockGuard lock(autocomplete.prefix_mutex);
LockGuard lock2(buffer_words_mutex);
autocomplete.prefix = get_buffer()->get_text(prefix_start, prefix_end); autocomplete.prefix = get_buffer()->get_text(prefix_start, prefix_end);
if(interactive_completion) if(interactive_completion)
@ -228,7 +222,6 @@ void Source::GenericView::setup_autocomplete() {
} }
} }
{ {
LockGuard lock(buffer_words_mutex);
for(auto &buffer_word : buffer_words) { for(auto &buffer_word : buffer_words) {
if((show_prefix_buffer_word || buffer_word.first.size() > prefix.size()) && if((show_prefix_buffer_word || buffer_word.first.size() > prefix.size()) &&
starts_with(buffer_word.first, prefix) && starts_with(buffer_word.first, prefix) &&

6
src/source_generic.hpp

@ -1,7 +1,6 @@
#pragma once #pragma once
#include "autocomplete.hpp" #include "autocomplete.hpp"
#include "mutex.hpp"
#include "source.hpp" #include "source.hpp"
#include <atomic> #include <atomic>
@ -17,9 +16,8 @@ namespace Source {
std::vector<std::pair<Gtk::TextIter, Gtk::TextIter>> get_words(const Gtk::TextIter &start, const Gtk::TextIter &end); std::vector<std::pair<Gtk::TextIter, Gtk::TextIter>> get_words(const Gtk::TextIter &start, const Gtk::TextIter &end);
Mutex buffer_words_mutex ACQUIRED_AFTER(autocomplete.prefix_mutex); std::map<std::string, size_t> buffer_words;
std::map<std::string, size_t> buffer_words GUARDED_BY(buffer_words_mutex); bool show_prefix_buffer_word = false; /// To avoid showing the current word if it is unique in document
bool show_prefix_buffer_word GUARDED_BY(buffer_words_mutex) = false; /// To avoid showing the current word if it is unique in document
void setup_buffer_words(); void setup_buffer_words();
Autocomplete autocomplete; Autocomplete autocomplete;

Loading…
Cancel
Save