Skip to content

Commit

Permalink
[dimension/indexOf] passes ticks as an rval ref to avoid copying
Browse files Browse the repository at this point in the history
  • Loading branch information
jgrewe committed Jul 28, 2020
1 parent 72558ee commit 7519868
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
18 changes: 9 additions & 9 deletions include/nix/Dimensions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ enum class PositionMatch {
* @brief Enumeration providing constants for range matching.
*
* These constants are used to control the behaviour of the range finding.
* Inclusive means [start, end], i.e. start and end are included
* Inclusive means [start, end], i.e. start and end are included
* Exclusive means [start, end), i.e. start is included, end is not
*/
enum class RangeMatch {
Expand All @@ -51,7 +51,7 @@ enum class PositionInRange{
InRange,
Greater,
Less,

NoRange = -1
};

Expand Down Expand Up @@ -709,10 +709,10 @@ class NIXAPI RangeDimension : public base::ImplContainer<base::IRangeDimension>
* Method will return the index of the tick that matches or is close to
* position. The way of matching can be controlled using the PositionMatch
* enum.
*
* @param position The position.
*
* @param position The position.
* @param matching PositionMatch enum entry that defines the matching
* behavior.
* behavior.
*
* @return boost optional containing the index if valid
*
Expand All @@ -729,25 +729,25 @@ class NIXAPI RangeDimension : public base::ImplContainer<base::IRangeDimension>
* @param start The start position
* @param end The end position
* @param ticks std::vector<double> of ticks, if empty ({}) they are automatically retrieved
* @param range RangeMatch enum, controls whether end is included or not,
* @param range RangeMatch enum, controls whether end is included or not,
* defaults to RangeMatch::Inclusive
*
* @return Start and end indices returned in a boost::optional<std::pair>
* which is invalid if out of range.
*/
boost::optional<std::pair<ndsize_t, ndsize_t>> indexOf(double start, double end,
std::vector<double> ticks,
std::vector<double> &&ticks,
RangeMatch match = RangeMatch::Inclusive) const;


/**
* @brief Returns the index of the given position
*
* Method will return the index of the tick that matches or is close to
* position. If "less_or_equal" is true, the index of the first tick that is
* less or equal is given. If "less_or_equal" is false the index of the
* first index that is greater than than position is returned.
*
*
* Version 1.4.5: The behavior of this function has been slightly changed,
* it now throws an OutOfBounds exception if the position is not in the
* range. Use positionInRange(position) to check before calling this function.
Expand Down
4 changes: 2 additions & 2 deletions src/Dimensions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ boost::optional<ndsize_t> RangeDimension::indexOf(const double position, Positio


boost::optional<std::pair<ndsize_t, ndsize_t>> RangeDimension::indexOf(double start, double end,
std::vector<double> ticks,
std::vector<double> &&ticks,
RangeMatch match) const {
if (ticks.size() == 0) {
ticks = this->ticks();
Expand Down Expand Up @@ -515,7 +515,7 @@ std::vector<std::pair<ndsize_t, ndsize_t>> RangeDimension::indexOf(const std::ve

for (size_t i = 0; i < start_positions.size(); ++i) {
boost::optional<std::pair<ndsize_t, ndsize_t>> range;
range = this->indexOf(start_positions[i], end_positions[i], ticks, match);
range = this->indexOf(start_positions[i], end_positions[i], std::move(ticks), match);
if (range) {
indices.push_back(*range);
}
Expand Down

0 comments on commit 7519868

Please sign in to comment.