Skip to content

Commit cf25d7a

Browse files
committed
[perf] detect_text_format() should check for valid utf-8 once
Also, turn of ASAN for distributed slices.
1 parent 0903263 commit cf25d7a

5 files changed

Lines changed: 38 additions & 30 deletions

File tree

src/base/distributed_slice.hh

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636

3737
#if defined(__APPLE__)
3838
# define DIST_SLICE(id) \
39-
__attribute__((used, \
39+
__attribute__((no_sanitize_address, \
40+
used, \
4041
section("__DATA,__ds_" DS_STRINGIZE( \
4142
id) ",regular,no_dead_strip")))
4243
# define DIST_SLICE_BEGIN(id) \
@@ -45,7 +46,8 @@
4546
__asm("section$end$__DATA$__ds_" DS_STRINGIZE(id))
4647
#else
4748
# define DIST_SLICE(id) \
48-
__attribute__((used, section("ds_" DS_STRINGIZE(id))))
49+
__attribute__(( \
50+
no_sanitize_address, used, section("ds_" DS_STRINGIZE(id))))
4951
# define DIST_SLICE_BEGIN(id) __asm("__start_ds_" DS_STRINGIZE(id))
5052
# define DIST_SLICE_END(id) __asm("__stop_ds_" DS_STRINGIZE(id))
5153
#endif
@@ -91,15 +93,9 @@ struct dist_slice_container {
9193
return this->sia_array[index];
9294
}
9395

94-
iterator begin()
95-
{
96-
return this->sia_array.begin();
97-
}
96+
iterator begin() { return this->sia_array.begin(); }
9897

99-
iterator end()
100-
{
101-
return this->sia_array.end();
102-
}
98+
iterator end() { return this->sia_array.end(); }
10399

104100
void clear()
105101
{

src/base/intern_string.hh

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -620,14 +620,15 @@ struct string_fragment {
620620
if (this->qs_in_escape) {
621621
this->qs_in_escape = false;
622622
return true;
623-
} else if (ch == '\\') {
623+
}
624+
if (ch == '\\') {
624625
this->qs_in_escape = true;
625626
return true;
626-
} else if (ch == '"') {
627+
}
628+
if (ch == '"') {
627629
return false;
628-
} else {
629-
return true;
630630
}
631+
return true;
631632
}
632633
};
633634

@@ -715,7 +716,7 @@ struct string_fragment {
715716
static_cast<std::string_view::size_type>(this->length())};
716717
}
717718

718-
enum class case_style {
719+
enum class case_style : uint8_t {
719720
lower,
720721
upper,
721722
camel,
@@ -732,8 +733,8 @@ struct string_fragment {
732733
}
733734

734735
const char* sf_string;
735-
int sf_begin;
736-
int sf_end;
736+
int32_t sf_begin;
737+
int32_t sf_end;
737738
};
738739

739740
inline bool

src/bookmarks.hh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,18 @@ public:
184184
static std::vector<string_fragment> get_type_names();
185185

186186
template<typename T, std::size_t N>
187-
explicit bookmark_type_t(const T (&name)[N])
187+
constexpr explicit bookmark_type_t(const T (&name)[N])
188188
: bt_name(string_fragment::from_const(name))
189189
{
190190
}
191191

192+
~bookmark_type_t() = default;
193+
192194
bookmark_type_t(const bookmark_type_t&) = delete;
193-
bookmark_type_t(const bookmark_type_t&&) = delete;
195+
bookmark_type_t(bookmark_type_t&&) = delete;
196+
197+
bookmark_type_t& operator=(const bookmark_type_t&) = delete;
198+
bookmark_type_t& operator=(bookmark_type_t&&) = delete;
194199

195200
const string_fragment& get_name() const { return this->bt_name; }
196201

src/lnav.ico

20.3 KB
Binary file not shown.

src/text_format.cc

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "text_format.hh"
3535

3636
#include "base/from_trait.hh"
37+
#include "base/is_utf8.hh"
3738
#include "base/itertools.enumerate.hh"
3839
#include "base/itertools.hh"
3940
#include "base/lnav_log.hh"
@@ -183,6 +184,11 @@ detect_text_format(string_fragment sf,
183184
)",
184185
PCRE2_MULTILINE | PCRE2_CASELESS | PCRE2_EXTENDED);
185186

187+
auto utf_res = is_utf8(sf);
188+
if (!utf_res.is_valid()) {
189+
return text_format_t::TF_UNKNOWN;
190+
}
191+
186192
if (path) {
187193
while (FILTER_EXTS.count(path->extension()) > 0) {
188194
path = path->stem();
@@ -256,47 +262,47 @@ detect_text_format(string_fragment sf,
256262
}
257263
}
258264

259-
if (DIFF_MATCHERS.find_in(sf).ignore_error()) {
265+
if (DIFF_MATCHERS.find_in(sf, PCRE2_NO_UTF_CHECK).ignore_error()) {
260266
return text_format_t::TF_DIFF;
261267
}
262268

263-
if (SH_MATCHERS.find_in(sf).ignore_error()) {
269+
if (SH_MATCHERS.find_in(sf, PCRE2_NO_UTF_CHECK).ignore_error()) {
264270
return text_format_t::TF_SHELL_SCRIPT;
265271
}
266272

267-
if (MAN_MATCHERS.find_in(sf).ignore_error()) {
273+
if (MAN_MATCHERS.find_in(sf, PCRE2_NO_UTF_CHECK).ignore_error()) {
268274
return text_format_t::TF_MAN;
269275
}
270276

271-
if (PYTHON_MATCHERS.find_in(sf).ignore_error()) {
277+
if (PYTHON_MATCHERS.find_in(sf, PCRE2_NO_UTF_CHECK).ignore_error()) {
272278
return text_format_t::TF_PYTHON;
273279
}
274280

275-
if (RUST_MATCHERS.find_in(sf).ignore_error()) {
281+
if (RUST_MATCHERS.find_in(sf, PCRE2_NO_UTF_CHECK).ignore_error()) {
276282
return text_format_t::TF_RUST;
277283
}
278284

279-
if (JAVA_MATCHERS.find_in(sf).ignore_error()) {
285+
if (JAVA_MATCHERS.find_in(sf, PCRE2_NO_UTF_CHECK).ignore_error()) {
280286
return text_format_t::TF_JAVA;
281287
}
282288

283-
if (C_LIKE_MATCHERS.find_in(sf).ignore_error()) {
289+
if (C_LIKE_MATCHERS.find_in(sf, PCRE2_NO_UTF_CHECK).ignore_error()) {
284290
return text_format_t::TF_C_LIKE;
285291
}
286292

287-
if (LNAV_MATCHERS.find_in(sf).ignore_error()) {
293+
if (LNAV_MATCHERS.find_in(sf, PCRE2_NO_UTF_CHECK).ignore_error()) {
288294
return text_format_t::TF_LNAV_SCRIPT;
289295
}
290296

291-
if (SQL_MATCHERS.find_in(sf).ignore_error()) {
297+
if (SQL_MATCHERS.find_in(sf, PCRE2_NO_UTF_CHECK).ignore_error()) {
292298
return text_format_t::TF_SQL;
293299
}
294300

295-
if (XML_MATCHERS.find_in(sf).ignore_error()) {
301+
if (XML_MATCHERS.find_in(sf, PCRE2_NO_UTF_CHECK).ignore_error()) {
296302
return text_format_t::TF_XML;
297303
}
298304

299-
if (INI_MATCHERS.find_in(sf).ignore_error()) {
305+
if (INI_MATCHERS.find_in(sf, PCRE2_NO_UTF_CHECK).ignore_error()) {
300306
return text_format_t::TF_INI;
301307
}
302308

0 commit comments

Comments
 (0)