Skip to content

Commit

Permalink
refactor(algo,dict): apply custom string algorithms to speed up some …
Browse files Browse the repository at this point in the history
…operations
  • Loading branch information
WhiredPlanck committed Jun 14, 2023
1 parent f9f76ee commit f65ea12
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
9 changes: 4 additions & 5 deletions src/rime/algo/encoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,20 @@
#include <utf8.h>
#include <rime/config.h>
#include <rime/algo/encoder.h>
#include <rime/algo/strings.h>

namespace rime {

static const int kEncoderDfsLimit = 32;
static const int kMaxPhraseLength = 32;

string RawCode::ToString() const {
return boost::join(*this, " ");
return strings::join(*this, " ");
}

void RawCode::FromString(const string &code_str) {
boost::split(*dynamic_cast<vector<string> *>(this),
code_str,
boost::algorithm::is_space(),
boost::algorithm::token_compress_on);
*dynamic_cast<vector<string> *>(this) =
strings::split(code_str, " ");
}

TableEncoder::TableEncoder(PhraseCollector* collector)
Expand Down
5 changes: 2 additions & 3 deletions src/rime/dict/entry_collector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <fstream>
#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
#include <rime/algo/strings.h>
#include <rime/dict/dict_settings.h>
#include <rime/dict/entry_collector.h>
#include <rime/dict/preset_vocabulary.h>
Expand Down Expand Up @@ -86,9 +87,7 @@ void EntryCollector::Collect(const string& dict_file) {
continue;
}
// read a dict entry
vector<string> row;
boost::algorithm::split(row, line,
boost::algorithm::is_any_of("\t"));
auto row = strings::split(line, "\t");
int num_columns = static_cast<int>(row.size());
if (num_columns <= text_column || row[text_column].empty()) {
LOG(WARNING) << "Missing entry text at #" << num_entries << ".";
Expand Down

0 comments on commit f65ea12

Please sign in to comment.