@@ -37,7 +37,7 @@ UsedLetters to_lower(UsedLetters letters)
37
37
using WordList = Vector<StringView>;
38
38
39
39
40
- static WordList get_words (const SharedString& content)
40
+ static WordList get_words (StringView content)
41
41
{
42
42
WordList res;
43
43
using Utf8It = utf8::iterator<const char *, utf8::InvalidPolicy::Pass>;
@@ -56,29 +56,36 @@ static WordList get_words(const SharedString& content)
56
56
{
57
57
const ByteCount start = word_start - content.begin ();
58
58
const ByteCount length = it.base () - word_start;
59
- res.push_back (content.acquire_substr (start, length));
59
+ res.push_back (content.substr (start, length));
60
60
in_word = false ;
61
61
}
62
62
}
63
63
return res;
64
64
}
65
65
66
- void WordDB::add_words (const SharedString& line)
66
+ void WordDB::add_words (StringView line)
67
67
{
68
68
for (auto & w : get_words (line))
69
69
{
70
- WordDB::WordInfo& info = m_words[SharedString{intern (w)}];
71
- ++info.refcount ;
72
- if (info.letters .none ())
70
+ auto it = m_words.find (w);
71
+ if (it == m_words.end ())
72
+ {
73
+ auto word = intern (w);
74
+ WordDB::WordInfo& info = m_words[word->strview ()];
75
+ info.word = word;
73
76
info.letters = used_letters (w);
77
+ ++info.refcount ;
78
+ }
79
+ else
80
+ ++ it->second .refcount ;
74
81
}
75
82
}
76
83
77
- void WordDB::remove_words (const SharedString& line)
84
+ void WordDB::remove_words (StringView line)
78
85
{
79
86
for (auto & w : get_words (line))
80
87
{
81
- auto it = m_words.find ({w, SharedString::NoCopy ()} );
88
+ auto it = m_words.find (w );
82
89
kak_assert (it != m_words.end () and it->second .refcount > 0 );
83
90
if (--it->second .refcount == 0 )
84
91
m_words.erase (it);
@@ -92,7 +99,7 @@ WordDB::WordDB(const Buffer& buffer)
92
99
for (auto line = 0_line, end = buffer.line_count (); line < end; ++line)
93
100
{
94
101
m_lines.push_back (buffer.line_storage (line));
95
- add_words (SharedString{ m_lines.back ()} );
102
+ add_words (m_lines.back ()-> strview () );
96
103
}
97
104
}
98
105
@@ -123,13 +130,13 @@ void WordDB::update_db()
123
130
while (old_line < modif.old_line + modif.num_removed )
124
131
{
125
132
kak_assert (old_line < m_lines.size ());
126
- remove_words (SharedString{ m_lines[(int )old_line++]} );
133
+ remove_words (m_lines[(int )old_line++]-> strview () );
127
134
}
128
135
129
136
for (auto l = 0_line; l < modif.num_added ; ++l)
130
137
{
131
138
new_lines.push_back (buffer.line_storage (modif.new_line + l));
132
- add_words (SharedString{ new_lines.back ()} );
139
+ add_words (new_lines.back ()-> strview () );
133
140
}
134
141
}
135
142
while (old_line != (int )m_lines.size ())
@@ -140,7 +147,7 @@ void WordDB::update_db()
140
147
141
148
int WordDB::get_word_occurences (StringView word) const
142
149
{
143
- auto it = m_words.find ({ word, SharedString::NoCopy ()} );
150
+ auto it = m_words.find (word);
144
151
if (it != m_words.end ())
145
152
return it->second .refcount ;
146
153
return 0 ;
0 commit comments