Skip to content

Commit

Permalink
Avoid temporary object
Browse files Browse the repository at this point in the history
Only occurs with clang >= 8.1.0 and -O2.

Fixes #2862.
  • Loading branch information
hadley committed Jun 14, 2017
1 parent 1be7aaf commit 0b40356
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions inst/include/dplyr/Result/Rank.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@ class RowNumber : public Result {

Slice slice(data, index);
// order( gdf.group(i) )
std::sort(tmp.begin(), tmp.begin() + m, Comparer(Visitor(slice)));
Visitor visitor(slice);
std::sort(tmp.begin(), tmp.begin() + m, Comparer(visitor));
int j = m - 1;
for (; j >= 0; j--) {
if (Rcpp::traits::is_na<RTYPE>(slice[ tmp[j] ])) {
Expand Down Expand Up @@ -289,7 +290,8 @@ class RowNumber : public Result {
if (nrows == 0) return IntegerVector(0);
IntegerVector x = seq(0, nrows - 1);
Slice slice(data, index);
std::sort(x.begin(), x.end(), Comparer(Visitor(slice)));
Visitor visitor(slice);
std::sort(x.begin(), x.end(), Comparer(visitor));
IntegerVector out = no_init(nrows);
int j = nrows - 1;
for (; j >= 0; j--) {
Expand Down Expand Up @@ -337,7 +339,8 @@ class Ntile : public Result {
Slice slice(data, index);

// order( gdf.group(i) )
std::sort(tmp.begin(), tmp.begin() + m, Comparer(Visitor(slice)));
Visitor visitor(slice);
std::sort(tmp.begin(), tmp.begin() + m, Comparer(visitor));
int j = m - 1;
for (; j >= 0; j--) {
if (Rcpp::traits::is_na<RTYPE>(slice[tmp[j]])) {
Expand Down

0 comments on commit 0b40356

Please sign in to comment.