Skip to content

Commit a2bb051

Browse files
authored
Merge pull request #43 from atom-ide-community/performance
2 parents 2e4fca5 + 0793026 commit a2bb051

File tree

8 files changed

+31
-41
lines changed

8 files changed

+31
-41
lines changed

.clang-tidy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
---
2-
Checks: "*, -clang-diagnostics-*-compat, -cppcoreguidelines-init-variables, -modernize-return-braced-init-list, -misc-unused-parameters, -misc-non-private-member-variables-in-classes, -llvmlibc-*, -llvm-header-guard, -llvm-include-order, -modernize-use-trailing-return-type, -readability-const-return-type, -readability-avoid-const-params-in-decls, -readability-convert-member-functions-to-static, -fuchsia-default-arguments-declarations, -fuchsia-default-arguments-calls, -*-uppercase-literal-suffix, -fuchsia-overloaded-operator, -google-build-using-namespace, -google-global-names-in-headers"
2+
Checks: "*, -clang-diagnostics-*-compat, -cppcoreguidelines-init-variables, -modernize-return-braced-init-list, -misc-unused-parameters, -misc-non-private-member-variables-in-classes, -llvmlibc-*, -llvm-header-guard, -llvm-include-order, -modernize-use-trailing-return-type, -readability-avoid-const-params-in-decls, -readability-convert-member-functions-to-static, -fuchsia-default-arguments-declarations, -fuchsia-default-arguments-calls, -*-uppercase-literal-suffix, -fuchsia-overloaded-operator, -google-build-using-namespace, -google-global-names-in-headers, -google-readability-todo"
33
HeaderFilterRegex: ".*"
44
FormatStyle: none

src/common.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef fuzzaldrin_common_h__
2-
#define fuzzaldrin_common_h__
1+
#ifndef Fuzzaldrin_common_h_
2+
#define Fuzzaldrin_common_h_
33

44
#include <vector>
55
#include <set>
@@ -20,8 +20,8 @@ constexpr size_t kMaxThreads = 16;
2020
// Safe string class that logs error when index is accessed outside the string.
2121
class SafeString : public std::string {
2222
public:
23-
SafeString() = default;
24-
SafeString(const std::string &s) : std::string(s) {}
23+
explicit SafeString() = default;
24+
explicit SafeString(const std::string &s) : std::string(s) {}
2525
const char &operator[](size_t i) const {
2626
if (i >= size()) {
2727
printf("ERROR string index access index=%zu str=%s\n", i, c_str());
@@ -53,7 +53,7 @@ struct PreparedQuery {
5353
Element ext;
5454
std::set<char> charCodes{};
5555

56-
PreparedQuery(const Element &q, const char pathSeparator);
56+
explicit PreparedQuery(const Element &q, const char pathSeparator);
5757
};
5858

5959
struct Options {
@@ -68,16 +68,16 @@ struct Options {
6868
#endif
6969
const PreparedQuery preparedQuery;
7070

71-
Options(const Element &_query, size_t _maxResults, bool _usePathScoring, bool _useExtensionBonus) : max_results(_maxResults), usePathScoring(_usePathScoring), useExtensionBonus(_useExtensionBonus), preparedQuery(_query, pathSeparator) {}
72-
Options(const Element &_query, char _pathSeparator) : pathSeparator(_pathSeparator), preparedQuery(_query, _pathSeparator) {}
71+
explicit Options(const Element &_query, size_t _maxResults, bool _usePathScoring, bool _useExtensionBonus) : max_results(_maxResults), usePathScoring(_usePathScoring), useExtensionBonus(_useExtensionBonus), preparedQuery(_query, pathSeparator) {}
72+
explicit Options(const Element &_query, char _pathSeparator) : pathSeparator(_pathSeparator), preparedQuery(_query, _pathSeparator) {}
7373
};
7474

7575
struct AcronymResult {
7676
Score score;
7777
float pos;
7878
int count;
7979

80-
AcronymResult(Score s, float p, int c) noexcept : score(s), pos(p), count(c) {}
80+
explicit AcronymResult(Score s, float p, int c) noexcept : score(s), pos(p), count(c) {}
8181
};
8282

8383
extern Element ToLower(const Element &s);
@@ -98,9 +98,9 @@ extern Score path_scorer_score(const CandidateString &string, const Element &que
9898
extern int countDir(const CandidateString &path, const size_t end, const char pathSeparator) noexcept;
9999
extern CandidateString getExtension(const CandidateString &str);
100100

101-
extern const std::vector<CandidateIndex> filter(const vector<std::vector<CandidateString>> &candidates, const Element &query, const Options &options);
101+
extern std::vector<CandidateIndex> filter(const vector<std::vector<CandidateString>> &candidates, const Element &query, const Options &options);
102102

103103
extern std::vector<size_t> matcher_match(const CandidateString &string, const Element &query, const Options &options);
104104
extern void get_wrap(const CandidateString &string, const Element &query, const Options &options, std::string *out);
105105

106-
#endif// fuzzaldrin_common_h__
106+
#endif// Fuzzaldrin_common_h_

src/filter.cc

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include <thread>
55
#include <limits>
66

7-
namespace {
87

98
struct CandidateScore {
109
// TODO non const
@@ -50,7 +49,7 @@ void thread_worker_filter(const std::vector<CandidateString> &candidates,
5049
filter_internal(candidates, start_index, query, options, max_results, results);
5150
}
5251

53-
const std::vector<CandidateIndex> sort_priority_queue(CandidateScorePriorityQueue &&candidates) {
52+
std::vector<CandidateIndex> sort_priority_queue(CandidateScorePriorityQueue &&candidates) {
5453
vector<CandidateScore> sorted;
5554
std::vector<CandidateIndex> ret;
5655
sorted.reserve(candidates.size());
@@ -61,14 +60,12 @@ const std::vector<CandidateIndex> sort_priority_queue(CandidateScorePriorityQueu
6160
}
6261
std::sort(sorted.begin(), sorted.end());
6362
for (const auto &item : sorted) {
64-
ret.push_back(item.index);
63+
ret.emplace_back(item.index);
6564
}
6665
return ret;
6766
}
6867

69-
}// namespace
70-
71-
const std::vector<CandidateIndex> filter(const vector<std::vector<CandidateString>> &candidates, const Element &query, const Options &options) {
68+
std::vector<CandidateIndex> filter(const vector<std::vector<CandidateString>> &candidates, const Element &query, const Options &options) {
7269
CandidateScorePriorityQueue top_k;
7370
auto max_results = options.max_results;
7471
if (max_results == 0u) {

src/fuzzaldrin.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Napi::Value Fuzzaldrin::setArrayFiltererCandidates(const Napi::CallbackInfo &inf
4444
}
4545
for (auto j = cur_start; j < cur_start + chunk_size; j++) {
4646
const Napi::Value val = candidates[j];
47-
candidates_[i].push_back(val.ToString().Utf8Value());
47+
candidates_[i].emplace_back(val.ToString().Utf8Value());
4848
}
4949
cur_start += chunk_size;
5050
}
@@ -80,7 +80,7 @@ Napi::Value Fuzzaldrin::setTreeFiltererCandidates(const Napi::CallbackInfo &info
8080
chunk_size++;
8181
}
8282
for (auto j = cur_start; j < cur_start + chunk_size; j++) {
83-
candidates_[i].push_back(candidates[j].data);// different // TODO copy
83+
candidates_[i].emplace_back(candidates[j].data);// different // TODO copy
8484
}
8585
cur_start += chunk_size;
8686
}

src/matcher.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ std::vector<size_t> computeMatch(const CandidateString &subject, const Candidate
117117
pos--;
118118
break;
119119
case Direction::DIAGONAL:
120-
matches.push_back(i + offset);
120+
matches.emplace_back(i + offset);
121121
j--;
122122
i--;
123123
pos -= n + 1;
@@ -192,14 +192,14 @@ std::vector<size_t> mergeMatches(const std::vector<size_t> &a, const std::vector
192192

193193
while (bj <= ai && ++j < n) {
194194
if (bj < ai) {
195-
out.push_back(bj);
195+
out.emplace_back(bj);
196196
}
197197
bj = b[j];
198198
}
199-
out.push_back(ai);
199+
out.emplace_back(ai);
200200
}
201201
while (j < n) {
202-
out.push_back(b[j++]);
202+
out.emplace_back(b[j++]);
203203
}
204204
return out;
205205
}

src/path_scorer.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
#include "common.h"
22

3-
namespace {
4-
53
// Directory depth at which the full path influence is halved.
64
constexpr size_t tau_depth = 20;
75

86
// Full path is also penalized for length of basename. This adjust a scale factor for that penalty.
97
constexpr Score file_coeff = 2.5;
108

11-
};// namespace
12-
13-
149
extern Score scorePath(const CandidateString &subject, const CandidateString &subject_lw, Score fullPathScore, const Options &options);
1510

1611
extern Score getExtensionScore(const CandidateString &candidate, const CandidateString &ext, const int startPos, const int endPos, const int maxDepth);

src/scorer.cc

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
// score: Find string similarity using a Smith Waterman algorithm
88
// Modified to account for programing scenarios (CamelCase folder/file.ext object.property)
99

10-
namespace {
11-
1210
// Base point for a single character match
1311
// This balance making patterns VS position and size penalty.
1412
constexpr int wm = 150;
@@ -28,16 +26,14 @@ constexpr Score tau_size = 150;
2826
// This has a direct influence on worst case scenario benchmark.
2927
constexpr float miss_coeff = 0.75;// Max number missed consecutive hit = ceil(miss_coeff*query.length) + 5
3028

31-
}// namespace
32-
3329
extern bool isWordEnd(const size_t pos, const CandidateString &subject, const CandidateString &subject_lw, const size_t len);
3430
extern bool isSeparator(const char c) noexcept;
3531
extern Score scoreExact(const size_t n, const size_t m, const size_t quality, const Score pos);
3632

3733
extern Score scorePattern(const size_t count, const size_t len, const size_t sameCase, const bool start, const bool end) noexcept;
3834
extern Score scoreExactMatch(const CandidateString &subject, const CandidateString &subject_lw, const Element &query, const Element &query_lw, size_t pos, const size_t n, const size_t m);
3935

40-
extern bool isAcronymFullWord(const CandidateString &subject, const CandidateString &subject_lw, const Element &query, const unsigned nbAcronymInQuery);
36+
extern bool isAcronymFullWord(const CandidateString &subject, const CandidateString &subject_lw, const Element &query, const unsigned nbAcronymInQuery) noexcept;
4137

4238

4339
//
@@ -535,7 +531,7 @@ AcronymResult scoreAcronyms(const CandidateString &subject, const CandidateStrin
535531
//
536532
// This method check for (b) assuming (a) has been checked before entering.
537533

538-
bool isAcronymFullWord(const CandidateString &subject, const CandidateString &subject_lw, const Element &query, const unsigned nbAcronymInQuery) {
534+
bool isAcronymFullWord(const CandidateString &subject, const CandidateString &subject_lw, const Element &query, const unsigned nbAcronymInQuery) noexcept {
539535
const auto m = subject.size();
540536
const auto n = query.size();
541537
auto count = 0u;

src/tree.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef fuzzaldrin_tree_h__
2-
#define fuzzaldrin_tree_h__
1+
#ifndef Fuzzaldrin_tree_h_
2+
#define Fuzzaldrin_tree_h_
33

44
#include <optional>
55
#include "common.h"
@@ -31,7 +31,7 @@ struct CandidateObject {
3131
const size_t level = 0;
3232
const size_t index = 0;
3333

34-
CandidateObject(CandidateString &&data_, const size_t level_, const size_t index_) noexcept
34+
explicit CandidateObject(CandidateString &&data_, const size_t level_, const size_t index_) noexcept
3535
: data{ move(data_) }, level{ level_ }, index{ index_ } {}
3636
};
3737

@@ -44,7 +44,9 @@ struct Tree {
4444

4545
/** Recursive function that fills the entriesArray from the given jsTreeArray */
4646
void makeEntriesArray(const Napi::Array &jsTreeArray, const size_t level) {
47-
for (auto iEntry = 0u, len = jsTreeArray.Length(); iEntry < len; iEntry++) {
47+
const auto entriesArrayLength = jsTreeArray.Length();
48+
entriesArray.reserve(entriesArrayLength);// reserve enough space
49+
for (auto iEntry = 0u; iEntry < entriesArrayLength; iEntry++) {
4850
auto jsTree = jsTreeArray[iEntry].As<Napi::Object>();
4951
makeEntriesArray(jsTree, level, iEntry);
5052
}
@@ -71,15 +73,15 @@ struct Tree {
7173
}
7274

7375
// default constructor is needed for generation of all the move/copy methods
74-
Tree() = default;
76+
explicit Tree() = default;
7577

7678
/** create a Tree object and make an entries array */
7779
// NOTE: this is made to only accept Napi::Array because we cannot export templates to JavaScript
78-
Tree(const Napi::Array &jsTreeArrayOrObject_, const string &dataKey_, const string &childrenKey_)
80+
explicit Tree(const Napi::Array &jsTreeArrayOrObject_, const string &dataKey_, const string &childrenKey_)
7981
: dataKey{ dataKey_ },
8082
childrenKey{ childrenKey_ } {
8183
makeEntriesArray(jsTreeArrayOrObject_, 0);
8284
}
8385
};
8486

85-
#endif// tree_h__
87+
#endif// Fuzzaldrin_tree_h_

0 commit comments

Comments
 (0)