Chromium Code Reviews| Index: Source/modules/gamepad/NavigatorGamepad.cpp |
| diff --git a/Source/modules/gamepad/NavigatorGamepad.cpp b/Source/modules/gamepad/NavigatorGamepad.cpp |
| index f0c840903e01c2528d944a8a25ac01bad9cbaab8..f56961b3f09808e6add91c535e72edc90399c8d3 100644 |
| --- a/Source/modules/gamepad/NavigatorGamepad.cpp |
| +++ b/Source/modules/gamepad/NavigatorGamepad.cpp |
| @@ -94,9 +94,22 @@ WebKitGamepadList* NavigatorGamepad::webkitGetGamepads(Navigator& navigator) |
| return NavigatorGamepad::from(navigator).webkitGamepads(); |
| } |
| -GamepadList* NavigatorGamepad::getGamepads(Navigator& navigator) |
| +HeapVector<Member<Gamepad>> NavigatorGamepad::getGamepads(Navigator& navigator) |
| { |
| - return NavigatorGamepad::from(navigator).gamepads(); |
| + GamepadList* gamepadList = NavigatorGamepad::from(navigator).gamepads(); |
| + unsigned length = gamepadList->length(); |
| + HeapVector<Member<Gamepad>> gamepads(length); |
| + unsigned actualLength = 0; |
| + for (unsigned i = 0; i < length; ++i) { |
| + Gamepad* gamepad = gamepadList->item(i); |
| + if (gamepad) { |
| + ASSERT(gamepad->index() == i); |
| + gamepads[i] = gamepad; |
|
kbalazs
2014/12/17 21:53:41
This should be gamepads[actualLength], no?
It see
philipj_slow
2014/12/17 22:45:38
This started out as a loop simply copying gamepads
kbalazs
2014/12/18 00:34:39
I see this in Vector::shrink:
TypeOperations::des
philipj_slow
2014/12/18 08:29:03
gamepad-polling-access.html tries exactly this, an
|
| + actualLength = i + 1; |
| + } |
| + } |
| + gamepads.shrink(actualLength); |
|
kbalazs
2014/12/17 21:53:41
In the common case this would allocate, deallocate
philipj_slow
2014/12/17 22:45:38
shrink() only modifies the size, it doesn't reallo
kbalazs
2014/12/18 00:34:39
Correct, it doesn't deallocate but it destroys ele
philipj_slow
2014/12/18 08:29:03
It's Member<Gamepad> being destroyed, so that seem
|
| + return gamepads; |
| } |
| WebKitGamepadList* NavigatorGamepad::webkitGamepads() |