Skip to content

Commit

Permalink
Pass gfx structs by const ref (gfx::Vector2d/F)
Browse files Browse the repository at this point in the history
Pass gfx structs by const ref (gfx::Vector2d/F)
Avoid unneccessary copy of structures gfx::Vector2d/F 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.

BUG=159273

Review URL: https://codereview.chromium.org/1112813003

Cr-Commit-Position: refs/heads/master@{#328104}
  • Loading branch information
a.berwal authored and Commit bot committed May 4, 2015
1 parent 6194a25 commit b98996a
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion ui/aura_extra/image_window_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class AURA_EXTRA_EXPORT ImageWindowDelegate : public aura::WindowDelegate {
void SetImage(const gfx::Image& image);

void set_background_color(SkColor color) { background_color_ = color; }
void set_image_offset(gfx::Vector2d offset) { offset_ = offset; }
void set_image_offset(const gfx::Vector2d& offset) { offset_ = offset; }

bool has_image() const { return !image_.IsEmpty(); }

Expand Down
2 changes: 1 addition & 1 deletion ui/compositor/layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ void Layer::SetBounds(const gfx::Rect& bounds) {
GetAnimator()->SetBounds(bounds);
}

void Layer::SetSubpixelPositionOffset(const gfx::Vector2dF offset) {
void Layer::SetSubpixelPositionOffset(const gfx::Vector2dF& offset) {
subpixel_position_offset_ = offset;
RecomputePosition();
}
Expand Down
2 changes: 1 addition & 1 deletion ui/compositor/layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class COMPOSITOR_EXPORT Layer

// The offset from our parent (stored in bounds.origin()) is an integer but we
// may need to be at a fractional pixel offset to align properly on screen.
void SetSubpixelPositionOffset(const gfx::Vector2dF offset);
void SetSubpixelPositionOffset(const gfx::Vector2dF& offset);
const gfx::Vector2dF& subpixel_position_offset() const {
return subpixel_position_offset_;
}
Expand Down
6 changes: 3 additions & 3 deletions ui/events/gesture_detection/velocity_tracker_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ class VelocityTrackerTest : public testing::Test {
static MockMotionEvent Sample(MotionEvent::Action action,
const gfx::PointF& p0,
TimeTicks t0,
gfx::Vector2dF v,
const gfx::Vector2dF& v,
TimeDelta dt) {
const gfx::PointF p = p0 + ScaleVector2d(v, dt.InSecondsF());
return MockMotionEvent(action, t0 + dt, p.x(), p.y());
}

static void ApplyMovementSequence(VelocityTrackerState* state,
const gfx::PointF& p0,
gfx::Vector2dF v,
const gfx::Vector2dF& v,
TimeTicks t0,
TimeDelta t,
size_t samples) {
Expand All @@ -73,7 +73,7 @@ class VelocityTrackerTest : public testing::Test {

static void ApplyMovement(VelocityTrackerState* state,
const gfx::PointF& p0,
gfx::Vector2dF v,
const gfx::Vector2dF& v,
TimeTicks t0,
TimeDelta t,
size_t samples) {
Expand Down
4 changes: 2 additions & 2 deletions ui/events/ozone/evdev/device_event_dispatcher_evdev.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ MouseWheelEventParams::~MouseWheelEventParams() {
ScrollEventParams::ScrollEventParams(int device_id,
EventType type,
const gfx::PointF location,
const gfx::Vector2dF delta,
const gfx::Vector2dF ordinal_delta,
const gfx::Vector2dF& delta,
const gfx::Vector2dF& ordinal_delta,
int finger_count,
const base::TimeDelta timestamp)
: device_id(device_id),
Expand Down
4 changes: 2 additions & 2 deletions ui/events/ozone/evdev/device_event_dispatcher_evdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ struct EVENTS_OZONE_EVDEV_EXPORT ScrollEventParams {
ScrollEventParams(int device_id,
EventType type,
const gfx::PointF location,
const gfx::Vector2dF delta,
const gfx::Vector2dF ordinal_delta,
const gfx::Vector2dF& delta,
const gfx::Vector2dF& ordinal_delta,
int finger_count,
const base::TimeDelta timestamp);
ScrollEventParams(const ScrollEventParams& other);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ gfx::Size GetExpandedWindowSize(DWORD window_style, gfx::Size size) {
return expanded;
}

void InsetBottomRight(gfx::Rect* rect, gfx::Vector2d vector) {
void InsetBottomRight(gfx::Rect* rect, const gfx::Vector2d& vector) {
rect->Inset(0, 0, vector.x(), vector.y());
}

Expand Down

0 comments on commit b98996a

Please sign in to comment.