Skip to content

Commit

Permalink
additionnal SymbolMap constructor to avoid using the expensive `inser…
Browse files Browse the repository at this point in the history
…t` method in a loop.

more efficient `LazySubsets` constructor.

#3335
  • Loading branch information
romainfrancois committed Apr 25, 2018
1 parent fbbf157 commit d21159a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 2 additions & 3 deletions inst/include/dplyr/Result/LazySubsets.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace dplyr {

class LazySubsets : public ILazySubsets {
public:
LazySubsets(const DataFrame& df) : nr(df.nrows()) {
LazySubsets(const DataFrame& df) : symbol_map(df.size(), df.names()), summary_map(), data(df.size()), nr(df.nrows()) {
int nvars = df.size();
if (nvars) {
CharacterVector names = df.names();
Expand All @@ -18,8 +18,7 @@ class LazySubsets : public ILazySubsets {
if (Rf_inherits(column, "matrix")) {
stop("matrix as column is not supported");
}
symbol_map.insert(names[i]);
data.push_back(df[i]);
data[i] = df[i];
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions inst/include/tools/SymbolMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ class SymbolMap {
public:
SymbolMap(): lookup(), names() {}

SymbolMap(int n, const CharacterVector& names_): lookup(n), names((SEXP)names_) {
for (int i = 0; i < n; i++) {
lookup.insert(std::make_pair(names_[i], i));
}
}

SymbolMap(const SymbolVector& names_): lookup(), names(names_) {}

SymbolMapIndex insert(const SymbolString& name) {
Expand Down

0 comments on commit d21159a

Please sign in to comment.