diff options
author | r.kasibhatla@samsung.com <r.kasibhatla@samsung.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-17 07:26:47 +0000 |
---|---|---|
committer | r.kasibhatla@samsung.com <r.kasibhatla@samsung.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-17 07:26:47 +0000 |
commit | 14bc5d68972f02676621c4d8087c428caff008c1 (patch) | |
tree | 8033616cbaceabbb6a921c7010c7ba5e63ced5e8 /cc/base | |
parent | 54facd633172b6d39c4f22edd9b976a39f468c45 (diff) | |
download | chromium_src-14bc5d68972f02676621c4d8087c428caff008c1.zip chromium_src-14bc5d68972f02676621c4d8087c428caff008c1.tar.gz chromium_src-14bc5d68972f02676621c4d8087c428caff008c1.tar.bz2 |
[#4] Pass gfx structs by const ref (gfx::PointF)
Avoid unneccessary copy of structures gfx::PointF
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 by value creates unneccessary overhead which should be avoided.
BUG=159273
R=danakj, enne, piman
Review URL: https://codereview.chromium.org/139233002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@245467 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/base')
-rw-r--r-- | cc/base/math_util.cc | 17 | ||||
-rw-r--r-- | cc/base/math_util.h | 8 |
2 files changed, 13 insertions, 12 deletions
diff --git a/cc/base/math_util.cc b/cc/base/math_util.cc index 23a9627..099a993 100644 --- a/cc/base/math_util.cc +++ b/cc/base/math_util.cc @@ -23,7 +23,7 @@ const float MathUtil::kPiFloat = 3.14159265358979323846f; static HomogeneousCoordinate ProjectHomogeneousPoint( const gfx::Transform& transform, - gfx::PointF p) { + const gfx::PointF& p) { // In this case, the layer we are trying to project onto is perpendicular to // ray (point p and z-axis direction) that we are trying to project. This // happens when the layer is rotated so that it is infinitesimally thin, or @@ -87,14 +87,14 @@ static inline void ExpandBoundsToIncludePoint(float* xmin, float* xmax, float* ymin, float* ymax, - gfx::PointF p) { + const gfx::PointF& p) { *xmin = std::min(p.x(), *xmin); *xmax = std::max(p.x(), *xmax); *ymin = std::min(p.y(), *ymin); *ymax = std::max(p.y(), *ymax); } -static inline void AddVertexToClippedQuad(gfx::PointF new_vertex, +static inline void AddVertexToClippedQuad(const gfx::PointF& new_vertex, gfx::PointF clipped_quad[8], int* num_vertices_in_clipped_quad) { clipped_quad[*num_vertices_in_clipped_quad] = new_vertex; @@ -223,8 +223,9 @@ void MathUtil::MapClippedQuad(const gfx::Transform& transform, DCHECK_LE(*num_vertices_in_clipped_quad, 8); } -gfx::RectF MathUtil::ComputeEnclosingRectOfVertices(gfx::PointF vertices[], - int num_vertices) { +gfx::RectF MathUtil::ComputeEnclosingRectOfVertices( + const gfx::PointF vertices[], + int num_vertices) { if (num_vertices < 2) return gfx::RectF(); @@ -356,7 +357,7 @@ gfx::QuadF MathUtil::MapQuad(const gfx::Transform& transform, } gfx::PointF MathUtil::MapPoint(const gfx::Transform& transform, - gfx::PointF p, + const gfx::PointF& p, bool* clipped) { HomogeneousCoordinate h = MapHomogeneousPoint(transform, gfx::Point3F(p)); @@ -421,7 +422,7 @@ gfx::QuadF MathUtil::ProjectQuad(const gfx::Transform& transform, } gfx::PointF MathUtil::ProjectPoint(const gfx::Transform& transform, - gfx::PointF p, + const gfx::PointF& p, bool* clipped) { HomogeneousCoordinate h = ProjectHomogeneousPoint(transform, p); @@ -551,7 +552,7 @@ bool MathUtil::FromValue(const base::Value* raw_value, gfx::Rect* out_rect) { return true; } -scoped_ptr<base::Value> MathUtil::AsValue(gfx::PointF pt) { +scoped_ptr<base::Value> MathUtil::AsValue(const gfx::PointF& pt) { scoped_ptr<base::ListValue> res(new base::ListValue()); res->AppendDouble(pt.x()); res->AppendDouble(pt.y()); diff --git a/cc/base/math_util.h b/cc/base/math_util.h index 53f4e85..c598fcf 100644 --- a/cc/base/math_util.h +++ b/cc/base/math_util.h @@ -116,7 +116,7 @@ class CC_EXPORT MathUtil { gfx::PointF clipped_quad[8], int* num_vertices_in_clipped_quad); - static gfx::RectF ComputeEnclosingRectOfVertices(gfx::PointF vertices[], + static gfx::RectF ComputeEnclosingRectOfVertices(const gfx::PointF vertices[], int num_vertices); static gfx::RectF ComputeEnclosingClippedRect( const HomogeneousCoordinate& h1, @@ -130,7 +130,7 @@ class CC_EXPORT MathUtil { const gfx::QuadF& quad, bool* clipped); static gfx::PointF MapPoint(const gfx::Transform& transform, - gfx::PointF point, + const gfx::PointF& point, bool* clipped); static gfx::Point3F MapPoint(const gfx::Transform&, const gfx::Point3F&, @@ -139,7 +139,7 @@ class CC_EXPORT MathUtil { const gfx::QuadF& quad, bool* clipped); static gfx::PointF ProjectPoint(const gfx::Transform& transform, - gfx::PointF point, + const gfx::PointF& point, bool* clipped); static gfx::Vector2dF ComputeTransform2dScaleComponents(const gfx::Transform&, @@ -169,7 +169,7 @@ class CC_EXPORT MathUtil { static scoped_ptr<base::Value> AsValue(const gfx::SizeF& s); static scoped_ptr<base::Value> AsValue(const gfx::Rect& r); static bool FromValue(const base::Value*, gfx::Rect* out_rect); - static scoped_ptr<base::Value> AsValue(gfx::PointF q); + static scoped_ptr<base::Value> AsValue(const gfx::PointF& q); static scoped_ptr<base::Value> AsValue(const gfx::QuadF& q); static scoped_ptr<base::Value> AsValue(const gfx::RectF& rect); static scoped_ptr<base::Value> AsValue(const gfx::Transform& transform); |