Skip to content

Commit 793c612

Browse files
committed
[attr_line] optimize split_lines
1 parent 797a5bd commit 793c612

14 files changed

+69
-36
lines changed

src/base/attr_line.cc

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "ansi_scrubber.hh"
3737
#include "auto_mem.hh"
3838
#include "config.h"
39+
#include "intervaltree/IntervalTree.h"
3940
#include "lnav_log.hh"
4041
#include "pcrepp/pcre2pp.hh"
4142

@@ -399,13 +400,43 @@ attr_line_t::subline(size_t start, size_t len) const
399400
void
400401
attr_line_t::split_lines(std::vector<attr_line_t>& lines) const
401402
{
403+
using line_type_t = interval_tree::Interval<size_t, attr_line_t>;
404+
using lines_tree_t = interval_tree::IntervalTree<size_t, attr_line_t>;
405+
406+
auto eols = std::vector<line_type_t>{};
402407
size_t pos = 0, next_line;
403408

404409
while ((next_line = this->al_string.find('\n', pos)) != std::string::npos) {
405-
lines.emplace_back(this->subline(pos, next_line - pos));
410+
eols.emplace_back(
411+
pos,
412+
next_line > pos ? next_line - 1 : next_line,
413+
attr_line_t{this->al_string.substr(pos, next_line - pos)});
406414
pos = next_line + 1;
407415
}
408-
lines.emplace_back(this->subline(pos));
416+
if (pos < this->al_string.length()) {
417+
eols.emplace_back(pos,
418+
this->al_string.length() - 1,
419+
attr_line_t{this->al_string.substr(pos)});
420+
}
421+
auto lines_tree = lines_tree_t{std::move(eols)};
422+
for (const auto& sa : this->al_attrs) {
423+
if (sa.sa_range.empty()) {
424+
continue;
425+
}
426+
auto range_end = sa.sa_range.end_for_string(this->al_string) - 1;
427+
lines_tree.visit_overlapping(
428+
sa.sa_range.lr_start, range_end, [&sa](const auto& cinterval) {
429+
auto& interval = const_cast<line_type_t&>(cinterval);
430+
auto lr = line_range(interval.start, interval.stop + 1);
431+
auto ilr = lr.intersection(sa.sa_range).shift(0, -lr.lr_start);
432+
interval.value.al_attrs.emplace_back(
433+
ilr, std::make_pair(sa.sa_type, sa.sa_value));
434+
});
435+
}
436+
lines_tree.visit_all([&lines](auto& cinterval) {
437+
auto& interval = const_cast<line_type_t&>(cinterval);
438+
lines.emplace_back(std::move(interval.value));
439+
});
409440
}
410441

411442
attr_line_t&

src/command_executor.cc

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,10 @@ using namespace lnav::roles::literals;
6565

6666
exec_context INIT_EXEC_CONTEXT;
6767

68+
static sig_atomic_t sql_counter = 0;
69+
6870
int
69-
sql_progress(const struct log_cursor& lc)
71+
sql_progress(const log_cursor& lc)
7072
{
7173
ssize_t total = lnav_data.ld_log_source.text_line_count();
7274
off_t off = lc.lc_curr_line;
@@ -83,8 +85,6 @@ sql_progress(const struct log_cursor& lc)
8385
return 1;
8486
}
8587

86-
static sig_atomic_t sql_counter = 0;
87-
8888
if (ui_periodic_timer::singleton().time_to_update(sql_counter)) {
8989
lnav_data.ld_bottom_source.update_loading(off, total);
9090
lnav_data.ld_status_refresher();
@@ -96,6 +96,12 @@ sql_progress(const struct log_cursor& lc)
9696
void
9797
sql_progress_finished()
9898
{
99+
if (sql_counter == 0) {
100+
return;
101+
}
102+
103+
sql_counter = 0;
104+
99105
if (lnav_data.ld_window == nullptr) {
100106
return;
101107
}
@@ -265,9 +271,9 @@ execute_search(const std::string& search_cmd)
265271
Result<std::string, lnav::console::user_message>
266272
execute_sql(exec_context& ec, const std::string& sql, std::string& alt_msg)
267273
{
268-
db_label_source& dls = *(ec.ec_label_source_stack.back());
274+
auto& dls = *(ec.ec_label_source_stack.back());
269275
auto_mem<sqlite3_stmt> stmt(sqlite3_finalize);
270-
struct timeval start_tv, end_tv;
276+
timeval start_tv, end_tv;
271277
std::string stmt_str = trim(sql);
272278
std::string retval;
273279
int retcode = SQLITE_OK;
@@ -516,7 +522,7 @@ execute_sql(exec_context& ec, const std::string& sql, std::string& alt_msg)
516522
} else {
517523
int row_count = dls.dls_rows.size();
518524
char row_count_buf[128];
519-
struct timeval diff_tv;
525+
timeval diff_tv;
520526

521527
timersub(&end_tv, &start_tv, &diff_tv);
522528
snprintf(row_count_buf,

src/internals/sql-ref.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,7 +1317,6 @@ fstat(*pattern*)
13171317
reason: No such file or directory
13181318
--> fstat:1
13191319
| SELECT ifnull(data, raise_error('cannot read: ' || st_name, error)) FROM fstat('/non-existent')
1320-
13211320

13221321

13231322
----
@@ -3290,7 +3289,6 @@ raise_error(*msg*, *\[reason\]*)
32903289
reason: because
32913290
--> raise_error:1
32923291
| SELECT ifnull($val, raise_error('please set $val', 'because'))
3293-
32943292

32953293

32963294
----

src/lnav.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,7 @@ VALUES ('org.lnav.mouse-support', -1, DATETIME('now', '+1 minute'),
12161216
auto _ign_signal = finally([] {
12171217
signal(SIGWINCH, SIG_IGN);
12181218
lnav_data.ld_winched = false;
1219+
lnav_data.ld_window = nullptr;
12191220
});
12201221

12211222
auto_fd errpipe[2];
@@ -1226,8 +1227,7 @@ VALUES ('org.lnav.mouse-support', -1, DATETIME('now', '+1 minute'),
12261227
auto pipe_err_handle
12271228
= log_pipe_err(errpipe[0].release(), errpipe[1].release());
12281229

1229-
notcurses_options nco;
1230-
memset(&nco, 0, sizeof(nco));
1230+
notcurses_options nco = {};
12311231
nco.flags |= NCOPTION_SUPPRESS_BANNERS | NCOPTION_NO_WINCH_SIGHANDLER;
12321232
nco.loglevel = NCLOGLEVEL_PANIC;
12331233
auto create_screen_res = screen_curses::create(nco);
@@ -3005,6 +3005,9 @@ SELECT tbl_name FROM sqlite_master WHERE sql LIKE 'CREATE VIRTUAL TABLE%'
30053005
.set_sub_source(&lnav_data.ld_hist_source2);
30063006
lnav_data.ld_views[LNV_DB].set_sub_source(&lnav_data.ld_db_row_source);
30073007
lnav_data.ld_db_overlay.dos_labels = &lnav_data.ld_db_row_source;
3008+
lnav_data.ld_db_example_row_source.dls_max_column_width = 15;
3009+
lnav_data.ld_db_example_overlay.dos_labels
3010+
= &lnav_data.ld_db_example_row_source;
30083011
lnav_data.ld_db_preview_overlay_source[0].dos_labels
30093012
= &lnav_data.ld_db_preview_source[0];
30103013
lnav_data.ld_db_preview_overlay_source[1].dos_labels

src/lnav.hh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ struct lnav_data_t {
234234

235235
db_label_source ld_db_row_source;
236236
db_overlay_source ld_db_overlay;
237+
db_label_source ld_db_example_row_source;
238+
db_overlay_source ld_db_example_overlay;
237239
db_label_source ld_db_preview_source[2];
238240
db_overlay_source ld_db_preview_overlay_source[2];
239241
std::vector<std::string> ld_db_key_names;

src/md2attr_line.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,9 @@ md2attr_line::leave_block(const md4cpp::event_handler::block& bl)
289289
new_block_text.append(line).append("\n");
290290
}
291291
}
292+
if (!cmd_block.empty()) {
293+
new_block_text.append(cmd_block);
294+
}
292295
block_text = new_block_text.move();
293296
}
294297

src/statusview_curses.hh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ private:
186186
status_data_source* sc_source{nullptr};
187187
ncplane* sc_window{nullptr};
188188
bool sc_enabled{true};
189-
role_t sc_default_role{role_t::VCR_STATUS};
190189

191190
struct displayed_field {
192191
displayed_field(line_range lr, size_t field_index)

src/view_helpers.cc

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,8 +1009,8 @@ execute_example(std::unordered_map<std::string, attr_line_t>& res_map,
10091009
return;
10101010
}
10111011

1012-
auto& dls = lnav_data.ld_db_row_source;
1013-
auto& dos = lnav_data.ld_db_overlay;
1012+
auto& dls = lnav_data.ld_db_example_row_source;
1013+
auto& dos = lnav_data.ld_db_example_overlay;
10141014
auto& db_tc = lnav_data.ld_views[LNV_DB];
10151015

10161016
for (const auto& [index, ex] : lnav::itertools::enumerate(ht.ht_example, 1)) {
@@ -1128,11 +1128,7 @@ eval_example(const help_text& ht, const help_example& ex)
11281128

11291129
switch (ht.ht_context) {
11301130
default: {
1131-
auto& dls = lnav_data.ld_db_row_source;
1132-
auto old_width = dls.dls_max_column_width;
1133-
dls.dls_max_column_width = 15;
11341131
execute_example(*res_map, ht);
1135-
dls.dls_max_column_width = old_width;
11361132
break;
11371133
}
11381134
}

test/expected/test_config.sh_a0907769aba112d628e7ebe39c4ec252e5e0bc69.err

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
 | parse error: object key and value must be separated by a colon (':')
4343
 |  "ui": "theme", "abc", "def": "" }
4444
 |  (right here) ------^
45-
 | 
4645
⚠ warning: unexpected value for property “/ui”
4746
 --> {test_dir}/bad-config2/formats/invalid-config/config.truncated.json:2
4847
 |  "ui": "theme" 

test/expected/test_format_loader.sh_5992e2695b7e6cf1f3520dbb87af8fc2b8f27088.err

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@
158158
semi  = “^(?<timestamp>\d+); (?<body>\w+)$”
159159
std  = “^(?<timestamp>\d+): (?<pid>\w+) (?<body>.*)$”
160160
with-level = “^(?<timestamp>\d+)\| (?<level>\w+) (?<body>\w+)$”
161-
162161
⚠ warning: invalid pattern: “/bad_sample_log/regex/semi”
163162
reason: pattern does not match any samples
164163
 --> {test_dir}/bad-config/formats/invalid-sample/format.json:10

0 commit comments

Comments
 (0)