Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[66_5] Perf tuning on tm_reader::decode via index_of #1649

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/Data/Convert/Texmacs/fromtm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,13 @@ tm_reader<format_without_utf8>::skip_blank () {
template <bool format_without_utf8>
string
tm_reader<format_without_utf8>::decode (string s) {
int i, n= N (s);
string r;
for (i= 0; i < n; i++)
if (((i + 1) < n) && (s[i] == '\\')) {
int start= index_of (s, '\\');
if (start == -1) return s;

int n= N (s), n_minus_one= n - 1, i= start;
string r= s (0, start);
for (; i < n_minus_one; i++)
da-liii marked this conversation as resolved.
Show resolved Hide resolved
if (s[i] == '\\') {
i++;
if (s[i] == ';')
;
Expand All @@ -92,6 +95,11 @@ tm_reader<format_without_utf8>::decode (string s) {
else r << s[i];
}
else r << s[i];
// if r[n-2] is not slash, i==n-1 and r[n-1] is not visited
if (i < n) {
jingkaimori marked this conversation as resolved.
Show resolved Hide resolved
r << s[i];
}

return r;
}

Expand Down Expand Up @@ -407,6 +415,7 @@ is_expand (tree t, string s, int n) {

tree
texmacs_document_to_tree (string s) {
bench_start ("tmdoc_to_tree_" * as_string (N (s)));
tree error (ERROR, "bad format or data");
if (starts (s, "edit") || starts (s, "TeXmacs") ||
starts (s, "\\(\\)(TeXmacs")) {
Expand Down Expand Up @@ -448,6 +457,7 @@ texmacs_document_to_tree (string s) {
d << A (doc);
doc= d;
}
bench_end ("tmdoc_to_tree_" * as_string (N (s)), 100);
return upgrade (doc, version);
}
return error;
Expand Down
41 changes: 41 additions & 0 deletions tests/Data/Convert/convert_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,23 @@

#include "base.hpp"
#include "convert.hpp"
#include "file.hpp"
#include "tree_helper.hpp"
Q_DECLARE_METATYPE (tree)
Q_DECLARE_METATYPE (string)
Q_DECLARE_METATYPE (url)

class TestConverter : public QObject {
Q_OBJECT

private slots:
void initTestCase () { init_lolly (); }
void test_search_metadata_data ();
void test_search_metadata ();
void test_texmacs_to_tree_data ();
void test_texmacs_to_tree ();
void test_texmacs_to_tree_bench_data ();
void test_texmacs_to_tree_bench ();
};

void
Expand Down Expand Up @@ -69,5 +76,39 @@ TestConverter::test_search_metadata () {
qcompare (search_metadata (input_tree, "invalid"), invalid);
}

void
TestConverter::test_texmacs_to_tree_data () {
QTest::addColumn<string> ("input_string");
QTest::addColumn<tree> ("output");

QTest::newRow ("pure string") << string ("text") << tree (DOCUMENT, "text");
QTest::newRow ("escaped string")
<< string ("tex\\\\t") << tree (DOCUMENT, "tex\\t");
QTest::newRow ("non escaped trailing slash")
<< string ("text\\") << tree (DOCUMENT, "text\\");
}
void
TestConverter::test_texmacs_to_tree () {
QFETCH (string, input_string);
QFETCH (tree, output);
QCOMPARE (texmacs_to_tree (input_string), output);
}

void
TestConverter::test_texmacs_to_tree_bench_data () {
QTest::addColumn<string> ("file_name");
url tm_base ("$TEXMACS_PATH/tests/tm/");
QTest::newRow ("29_1_1.tm") << string ("$TEXMACS_PATH/tests/tm/29_1_1.tm");
QTest::newRow ("46_3.tm") << string ("$TEXMACS_PATH/tests/tm/46_3.tm");
QTest::newRow ("64_1.tm") << string ("$TEXMACS_PATH/tests/tm/64_1.tm");
}
void
TestConverter::test_texmacs_to_tree_bench () {
QFETCH (string, file_name);
string file_content;
load_string (file_name, file_content, true);
QBENCHMARK { texmacs_to_tree (file_content); };
}

QTEST_MAIN (TestConverter)
#include "convert_test.moc"
Loading