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

Commit

Permalink
Performance
Browse files Browse the repository at this point in the history
  • Loading branch information
dail8859 committed Aug 16, 2016
1 parent 6f18e87 commit 36e1619
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 32 deletions.
51 changes: 23 additions & 28 deletions src/ElasticTabstops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ static int get_text_width(sptr_t edit, int start, int end)

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

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

Expand Down Expand Up @@ -120,32 +123,27 @@ static int get_block_boundary(sptr_t edit, int& location, direction which_dir)
location = get_line_start(edit, location);
do
{
int tabs_on_line = 0;

int current_pos = location;
unsigned char current_char = (unsigned char)call_edit(edit, SCI_GETCHARAT, current_pos);
bool current_char_ends_line = is_line_end(edit, current_pos);
int line_end = get_line_end(edit, current_pos);
int tabs_on_line = 0;

while (current_char != '\0' && !current_char_ends_line)
while (current_char != '\0' && current_pos != line_end)
{
if (current_char == '\t')
{
tabs_on_line++;
if (tabs_on_line > max_tabs)
{
max_tabs = tabs_on_line;
}
}

current_pos = call_edit(edit, SCI_POSITIONAFTER, current_pos);
current_char = (unsigned char)call_edit(edit, SCI_GETCHARAT, current_pos);
current_char_ends_line = is_line_end(edit, current_pos);
}
if (tabs_on_line == 0 && !orig_line)
{
return max_tabs;
}

if (tabs_on_line > max_tabs) max_tabs = tabs_on_line;

if (tabs_on_line == 0 && !orig_line) return max_tabs;

orig_line = false;
} while (change_line(edit, location, which_dir));

return max_tabs;
}

Expand All @@ -157,24 +155,22 @@ static int get_nof_tabs_between(sptr_t edit, int start, int end)
do
{
unsigned char current_char = (unsigned char)call_edit(edit, SCI_GETCHARAT, current_pos);
bool current_char_ends_line = is_line_end(edit, current_pos);

int line_end = get_line_end(edit, current_pos);
int tabs_on_line = 0;
while (current_char != '\0' && !current_char_ends_line)

while (current_char != '\0' && current_pos != line_end)
{
if (current_char == '\t')
{
tabs_on_line++;
if (tabs_on_line > max_tabs)
{
max_tabs = tabs_on_line;
}
}

current_pos = call_edit(edit, SCI_POSITIONAFTER, current_pos);
current_char = (unsigned char)call_edit(edit, SCI_GETCHARAT, current_pos);
current_char_ends_line = is_line_end(edit, current_pos);
}

if (tabs_on_line > max_tabs) max_tabs = tabs_on_line;

} while (change_line(edit, current_pos, FORWARDS) && current_pos < end);

return max_tabs;
}

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

while (current_char != '\0')
{
if (current_char_ends_line)
if (current_pos == line_end)
{
grid[l][current_tab_num].ends_in_tab = false;
text_width_in_tab = 0;
Expand Down Expand Up @@ -234,7 +230,6 @@ static void stretch_tabstops(sptr_t edit, int block_start_linenum, int block_nof
}
current_pos = call_edit(edit, SCI_POSITIONAFTER, current_pos);
current_char = (unsigned char)call_edit(edit, SCI_GETCHARAT, current_pos);
current_char_ends_line = is_line_end(edit, current_pos);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

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

0 comments on commit 36e1619

Please sign in to comment.