-
Notifications
You must be signed in to change notification settings - Fork 573
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(dict): improve dict complile performance (#663)
* refactor(utilities.cc): speed up processing of Checksum * feat,refactor(dict): tweak to speed up EncodePhrase - Replace map with unordered_map for related data structs - Replace boost::lexicast to std::stox This may save 8 % ~ 10 % of the build time of the dictionaries. * feat(algo): add custom string algorithms * refactor(algo,dict): apply custom string algorithms to speed up some operations * refactor(strings.cc/.h): remove unnecessary `RIME_API` modifiers
- Loading branch information
1 parent
6772e2d
commit bd3c7c7
Showing
7 changed files
with
97 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include <rime/algo/strings.h> | ||
|
||
namespace rime { | ||
namespace strings { | ||
|
||
vector<string> split(const string& str, const string& delim, SplitBehavior behavior) { | ||
vector<string> strings; | ||
size_t lastPos, pos; | ||
if (behavior == SplitBehavior::SkipEmpty) { | ||
lastPos = str.find_first_not_of(delim, 0); | ||
} else { | ||
lastPos = 0; | ||
} | ||
pos = str.find_first_of(delim, lastPos); | ||
|
||
while (std::string::npos != pos || std::string::npos != lastPos) { | ||
strings.emplace_back(str.substr(lastPos, pos - lastPos)); | ||
if (behavior == SplitBehavior::SkipEmpty) { | ||
lastPos = str.find_first_not_of(delim, pos); | ||
} else { | ||
if (pos == std::string::npos) { | ||
break; | ||
} | ||
lastPos = pos + 1; | ||
} | ||
pos = str.find_first_of(delim, lastPos); | ||
} | ||
return strings; | ||
}; | ||
|
||
vector<string> split(const string& str, const string& delim) { | ||
return split(str, delim, SplitBehavior::SkipEmpty); | ||
}; | ||
|
||
} // namespace strings | ||
} // namespace rime | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#ifndef RIME_STRINGS_H_ | ||
#define RIME_STRINGS_H_ | ||
|
||
#include <rime/common.h> | ||
#include <initializer_list> | ||
|
||
namespace rime { | ||
namespace strings { | ||
|
||
enum class SplitBehavior { KeepEmpty, SkipEmpty }; | ||
|
||
vector<string> split(const string& str, const string& delim, SplitBehavior behavior); | ||
|
||
vector<string> split(const string& str, const string& delim); | ||
|
||
template <typename Iter, typename T> | ||
string join(Iter start, Iter end, T &&delim) { | ||
string result; | ||
if (start != end) { | ||
result += (*start); | ||
start++; | ||
} | ||
for (; start != end; start++) { | ||
result += (delim); | ||
result += (*start); | ||
} | ||
return result; | ||
} | ||
|
||
template <typename C, typename T> | ||
inline string join(C &&container, T &&delim) { | ||
return join(std::begin(container), std::end(container), delim); | ||
} | ||
|
||
template <typename C, typename T> | ||
inline string join(std::initializer_list<C> &&container, T &&delim) { | ||
return join(std::begin(container), std::end(container), delim); | ||
} | ||
|
||
} // namespace strings | ||
} // namespace rime | ||
|
||
#endif // RIME_STRINGS_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters