From 0a28c1822fb06b7e178b73225d032793679a3482 Mon Sep 17 00:00:00 2001 From: eidheim Date: Mon, 2 Aug 2021 18:23:24 +0200 Subject: [PATCH] Removed unnecessary mutex from GenericView --- src/source_generic.cpp | 9 +-------- src/source_generic.hpp | 6 ++---- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/src/source_generic.cpp b/src/source_generic.cpp index 4b34f2e..9ad86a7 100644 --- a/src/source_generic.cpp +++ b/src/source_generic.cpp @@ -87,7 +87,6 @@ std::vector> Source::GenericView::get_wo void Source::GenericView::setup_buffer_words() { { auto words = get_words(get_buffer()->begin(), get_buffer()->end()); - LockGuard lock(buffer_words_mutex); for(auto &word : words) { auto result = buffer_words.emplace(get_buffer()->get_text(word.first, word.second), 1); if(!result.second) @@ -105,7 +104,6 @@ void Source::GenericView::setup_buffer_words() { if(is_token_char(*iter)) { auto word = get_token_iters(iter); 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)); if(it != buffer_words.end()) { if(it->second > 1) @@ -128,7 +126,6 @@ void Source::GenericView::setup_buffer_words() { end.forward_char(); auto words = get_words(start, end); - LockGuard lock(buffer_words_mutex); for(auto &word : words) { auto result = buffer_words.emplace(get_buffer()->get_text(word.first, word.second), 1); if(!result.second) @@ -145,7 +142,6 @@ void Source::GenericView::setup_buffer_words() { start.backward_char(); end.forward_char(); auto words = get_words(start, end); - LockGuard lock(buffer_words_mutex); for(auto &word : words) { auto it = buffer_words.find(get_buffer()->get_text(word.first, word.second)); if(it != buffer_words.end()) { @@ -166,7 +162,6 @@ void Source::GenericView::setup_buffer_words() { if(is_token_char(*start)) { auto word = get_token_iters(start); 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); if(!result.second) ++(result.first->second); @@ -194,8 +189,7 @@ void Source::GenericView::setup_autocomplete() { prefix_start.forward_char(); if((count >= 3 && !(*prefix_start >= '0' && *prefix_start <= '9')) || !interactive_completion) { - LockGuard lock1(autocomplete.prefix_mutex); - LockGuard lock2(buffer_words_mutex); + LockGuard lock(autocomplete.prefix_mutex); autocomplete.prefix = get_buffer()->get_text(prefix_start, prefix_end); if(interactive_completion) @@ -228,7 +222,6 @@ void Source::GenericView::setup_autocomplete() { } } { - LockGuard lock(buffer_words_mutex); for(auto &buffer_word : buffer_words) { if((show_prefix_buffer_word || buffer_word.first.size() > prefix.size()) && starts_with(buffer_word.first, prefix) && diff --git a/src/source_generic.hpp b/src/source_generic.hpp index 3942890..8e1ebbb 100644 --- a/src/source_generic.hpp +++ b/src/source_generic.hpp @@ -1,7 +1,6 @@ #pragma once #include "autocomplete.hpp" -#include "mutex.hpp" #include "source.hpp" #include @@ -17,9 +16,8 @@ namespace Source { std::vector> get_words(const Gtk::TextIter &start, const Gtk::TextIter &end); - Mutex buffer_words_mutex ACQUIRED_AFTER(autocomplete.prefix_mutex); - std::map buffer_words GUARDED_BY(buffer_words_mutex); - bool show_prefix_buffer_word GUARDED_BY(buffer_words_mutex) = false; /// To avoid showing the current word if it is unique in document + std::map buffer_words; + bool show_prefix_buffer_word = false; /// To avoid showing the current word if it is unique in document void setup_buffer_words(); Autocomplete autocomplete;