Skip to content
This repository was archived by the owner on Dec 6, 2022. It is now read-only.

Commit 36e1619

Browse files
committed
Performance
1 parent 6f18e87 commit 36e1619

File tree

2 files changed

+27
-32
lines changed

2 files changed

+27
-32
lines changed

src/ElasticTabstops.cpp

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ static int get_text_width(sptr_t edit, int start, int end)
8282

8383
LONG_PTR style = call_edit(edit, SCI_GETSTYLEAT, start);
8484

85+
// NOTE: the width is measured in case proportional fonts are used.
86+
// If we assume monospaced fonts we could simplify measuring text widths eg (end-start)*char_width
87+
// But for now performance shouldn't be too much of an issue
8588
return call_edit(edit, SCI_TEXTWIDTH, style, (LONG_PTR)range.lpstrText);
8689
}
8790

@@ -120,32 +123,27 @@ static int get_block_boundary(sptr_t edit, int& location, direction which_dir)
120123
location = get_line_start(edit, location);
121124
do
122125
{
123-
int tabs_on_line = 0;
124-
125126
int current_pos = location;
126127
unsigned char current_char = (unsigned char)call_edit(edit, SCI_GETCHARAT, current_pos);
127-
bool current_char_ends_line = is_line_end(edit, current_pos);
128+
int line_end = get_line_end(edit, current_pos);
129+
int tabs_on_line = 0;
128130

129-
while (current_char != '\0' && !current_char_ends_line)
131+
while (current_char != '\0' && current_pos != line_end)
130132
{
131133
if (current_char == '\t')
132-
{
133134
tabs_on_line++;
134-
if (tabs_on_line > max_tabs)
135-
{
136-
max_tabs = tabs_on_line;
137-
}
138-
}
135+
139136
current_pos = call_edit(edit, SCI_POSITIONAFTER, current_pos);
140137
current_char = (unsigned char)call_edit(edit, SCI_GETCHARAT, current_pos);
141-
current_char_ends_line = is_line_end(edit, current_pos);
142-
}
143-
if (tabs_on_line == 0 && !orig_line)
144-
{
145-
return max_tabs;
146138
}
139+
140+
if (tabs_on_line > max_tabs) max_tabs = tabs_on_line;
141+
142+
if (tabs_on_line == 0 && !orig_line) return max_tabs;
143+
147144
orig_line = false;
148145
} while (change_line(edit, location, which_dir));
146+
149147
return max_tabs;
150148
}
151149

@@ -157,24 +155,22 @@ static int get_nof_tabs_between(sptr_t edit, int start, int end)
157155
do
158156
{
159157
unsigned char current_char = (unsigned char)call_edit(edit, SCI_GETCHARAT, current_pos);
160-
bool current_char_ends_line = is_line_end(edit, current_pos);
161-
158+
int line_end = get_line_end(edit, current_pos);
162159
int tabs_on_line = 0;
163-
while (current_char != '\0' && !current_char_ends_line)
160+
161+
while (current_char != '\0' && current_pos != line_end)
164162
{
165163
if (current_char == '\t')
166-
{
167164
tabs_on_line++;
168-
if (tabs_on_line > max_tabs)
169-
{
170-
max_tabs = tabs_on_line;
171-
}
172-
}
165+
173166
current_pos = call_edit(edit, SCI_POSITIONAFTER, current_pos);
174167
current_char = (unsigned char)call_edit(edit, SCI_GETCHARAT, current_pos);
175-
current_char_ends_line = is_line_end(edit, current_pos);
176168
}
169+
170+
if (tabs_on_line > max_tabs) max_tabs = tabs_on_line;
171+
177172
} while (change_line(edit, current_pos, FORWARDS) && current_pos < end);
173+
178174
return max_tabs;
179175
}
180176

@@ -200,12 +196,12 @@ static void stretch_tabstops(sptr_t edit, int block_start_linenum, int block_nof
200196
int current_pos = call_edit(edit, SCI_POSITIONFROMLINE, current_line_num);
201197
int cell_start = current_pos;
202198
unsigned char current_char = (unsigned char)call_edit(edit, SCI_GETCHARAT, current_pos);
203-
bool current_char_ends_line = is_line_end(edit, current_pos);
199+
int line_end = get_line_end(edit, current_pos);
204200
// maybe change this to search forwards for tabs/newlines
205201

206202
while (current_char != '\0')
207203
{
208-
if (current_char_ends_line)
204+
if (current_pos == line_end)
209205
{
210206
grid[l][current_tab_num].ends_in_tab = false;
211207
text_width_in_tab = 0;
@@ -234,7 +230,6 @@ static void stretch_tabstops(sptr_t edit, int block_start_linenum, int block_nof
234230
}
235231
current_pos = call_edit(edit, SCI_POSITIONAFTER, current_pos);
236232
current_char = (unsigned char)call_edit(edit, SCI_GETCHARAT, current_pos);
237-
current_char_ends_line = is_line_end(edit, current_pos);
238233
}
239234
}
240235

src/Version.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
// along with this program; if not, write to the Free Software
1717
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1818

19-
#define VERSION_NUM 1,0,1,0
20-
#define VERSION_LINEAR 1010
21-
#define VERSION_LINEAR_TEXT TEXT("1010")
22-
#define VERSION_TEXT TEXT("1.0.1") // This must match the tag pushed on the server minus the "v"
19+
#define VERSION_NUM 1,0,2,0
20+
#define VERSION_LINEAR 1020
21+
#define VERSION_LINEAR_TEXT TEXT("1020")
22+
#define VERSION_TEXT TEXT("1.0.2") // This must match the tag pushed on the server minus the "v"
2323
#define VERSION_STAGE TEXT("") // "alpha", "beta", ""

0 commit comments

Comments
 (0)