diff options
author | ajay.berwal@samsung.com <ajay.berwal@samsung.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-23 10:39:12 +0000 |
---|---|---|
committer | ajay.berwal@samsung.com <ajay.berwal@samsung.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-23 10:39:12 +0000 |
commit | 3244c913f7fc31c43107ffd895c786f26b892c07 (patch) | |
tree | 15f33a1820994df0998f7be8b89740f82dbde1ed /cc/base | |
parent | 8aaf0f58eb8b532a4190a55c753f4796d7515933 (diff) | |
download | chromium_src-3244c913f7fc31c43107ffd895c786f26b892c07.zip chromium_src-3244c913f7fc31c43107ffd895c786f26b892c07.tar.gz chromium_src-3244c913f7fc31c43107ffd895c786f26b892c07.tar.bz2 |
Pass gfx structs by const ref (gfx::Vector2dF)
Avoid unneccessary copy of structures gfx::Vector2dF
by passing them by const ref rather than value.
Any struct of size > 4 bytes should be passed by const ref.
Passing by ref for these structs is faster than passing
by value, especially when invoking function has multiple parameters.
Pass gfx structs by const ref (gfx::Vector2dF)
BUG=159273
Review URL: https://codereview.chromium.org/130443005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@246563 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/base')
-rw-r--r-- | cc/base/math_util.cc | 8 | ||||
-rw-r--r-- | cc/base/math_util.h | 8 |
2 files changed, 8 insertions, 8 deletions
diff --git a/cc/base/math_util.cc b/cc/base/math_util.cc index 099a993..8abfa90f0 100644 --- a/cc/base/math_util.cc +++ b/cc/base/math_util.cc @@ -492,16 +492,16 @@ gfx::Vector2dF MathUtil::ComputeTransform2dScaleComponents( return gfx::Vector2dF(x_scale, y_scale); } -float MathUtil::SmallestAngleBetweenVectors(gfx::Vector2dF v1, - gfx::Vector2dF v2) { +float MathUtil::SmallestAngleBetweenVectors(const gfx::Vector2dF& v1, + const gfx::Vector2dF& v2) { double dot_product = gfx::DotProduct(v1, v2) / v1.Length() / v2.Length(); // Clamp to compensate for rounding errors. dot_product = std::max(-1.0, std::min(1.0, dot_product)); return static_cast<float>(Rad2Deg(std::acos(dot_product))); } -gfx::Vector2dF MathUtil::ProjectVector(gfx::Vector2dF source, - gfx::Vector2dF destination) { +gfx::Vector2dF MathUtil::ProjectVector(const gfx::Vector2dF& source, + const gfx::Vector2dF& destination) { float projected_length = gfx::DotProduct(source, destination) / destination.LengthSquared(); return gfx::Vector2dF(projected_length * destination.x(), diff --git a/cc/base/math_util.h b/cc/base/math_util.h index c598fcf..6cad1ad 100644 --- a/cc/base/math_util.h +++ b/cc/base/math_util.h @@ -156,13 +156,13 @@ class CC_EXPORT MathUtil { // Returns the smallest angle between the given two vectors in degrees. // Neither vector is assumed to be normalized. - static float SmallestAngleBetweenVectors(gfx::Vector2dF v1, - gfx::Vector2dF v2); + static float SmallestAngleBetweenVectors(const gfx::Vector2dF& v1, + const gfx::Vector2dF& v2); // Projects the |source| vector onto |destination|. Neither vector is assumed // to be normalized. - static gfx::Vector2dF ProjectVector(gfx::Vector2dF source, - gfx::Vector2dF destination); + static gfx::Vector2dF ProjectVector(const gfx::Vector2dF& source, + const gfx::Vector2dF& destination); // Conversion to value. static scoped_ptr<base::Value> AsValue(gfx::Size s); |