From de6749fed7b7142c7c97d7b15f106ae58e2e65c1 Mon Sep 17 00:00:00 2001 From: Stefan Ravn van Overeem Date: Tue, 27 Jun 2023 22:32:57 +0200 Subject: [PATCH] Improve unicode codepoint Bisearch performance (#691) Improve the performance of the functions for searching for codepoints in a table by passing the table array in as a reference instead of copying it. Co-authored-by: ArthurSonzogni --- src/ftxui/dom/benchmark_test.cpp | 13 +++++++++++++ src/ftxui/screen/string.cpp | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/ftxui/dom/benchmark_test.cpp b/src/ftxui/dom/benchmark_test.cpp index 740e8f5..f341d5f 100644 --- a/src/ftxui/dom/benchmark_test.cpp +++ b/src/ftxui/dom/benchmark_test.cpp @@ -29,6 +29,19 @@ static void BencharkBasic(benchmark::State& state) { } BENCHMARK(BencharkBasic)->DenseRange(0, 256, 16); +static void BencharkText(benchmark::State& state) { + while (state.KeepRunning()) { + std::string content = "HELLO world "; + for(int i=0; iDenseRange(0, 10, 1); + } // namespace ftxui // Copyright 2021 Arthur Sonzogni. All rights reserved. diff --git a/src/ftxui/screen/string.cpp b/src/ftxui/screen/string.cpp index ad52bb3..06dd0e4 100644 --- a/src/ftxui/screen/string.cpp +++ b/src/ftxui/screen/string.cpp @@ -1480,7 +1480,7 @@ const std::array g_word_break_intervals = {{ // Find a codepoint inside a sorted list of Interval. template -bool Bisearch(uint32_t ucs, const std::array table) { +bool Bisearch(uint32_t ucs, const std::array& table) { if (ucs < table.front().first || ucs > table.back().last) { // NOLINT return false; } @@ -1503,7 +1503,7 @@ bool Bisearch(uint32_t ucs, const std::array table) { // Find a value inside a sorted list of Interval + property. template -bool Bisearch(uint32_t ucs, const std::array table, C* out) { +bool Bisearch(uint32_t ucs, const std::array& table, C* out) { if (ucs < table.front().first || ucs > table.back().last) { // NOLINT return false; }