Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce copying in API parameter constructors #5926

Merged
merged 1 commit into from
Jan 21, 2021

Conversation

mjjbell
Copy link
Member

@mjjbell mjjbell commented Jan 6, 2021

Issue

When using non-default constructors for the API parameter classes, vector arguments like coordinates and hints are copied at least once (twice when passed as lvalue arguments).

This PR enables perfect forwarding of BaseParameters arguments and pass-by-value/move in the constructor that uses the argument. This ensures we copy at most once (zero for rvalue arguments).

There is one case that I have omitted from forwarding - waypoints in MatchParameters, which inherits from RouteParameters and has a slightly different argument order that complicates things. I've left it as-is for readability.

Impact

This will have no effect on requests made to osrm-routed or via NodeJS bindings as they both use the default constructor and build parameters incrementally. It only impacts libosrm API usage of non-default *Parameters constructors.

Requirements / Relations

There is previous discussion in #2991 about enabling perfect forwarding in these constructors, suggesting this would break the libosrm API. Unless this is referring to a binary compatibility issue which I'm not aware of, I don't think this is a problem.

With this change, lvalue arguments will still be copied, and rvalue arguments will be moved from, which should meet the expectation of the caller.

Tasklist

When using non-default constructors for the API parameter classes,
vector arguments like coordinates and hints are copied at least once
(twice when passed as lvalue arguments).

Enable perfect forwarding of BaseParameter arguments and
pass-by-value in the constructor that uses the argument. This
ensures we copy at most once (zero for rvalue arguments).
Copy link
Contributor

@akashihi akashihi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks safe and clear

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants