Skip to content

Commit bef7cfb

Browse files
committed
perf(drag-drop): use narrower check for touch events
We use the `isTouchEvent` any time we need to normalize something between touch and mouse events which happens for every pixel that the user has dragged. These changes switch to using direct comparison, rather than `startsWith`, which should be slightly faster since there's a narrow set of touch event types.
1 parent 0908be7 commit bef7cfb

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/cdk/drag-drop/drag-ref.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,10 @@ function removeElement(element: HTMLElement | null) {
11031103

11041104
/** Determines whether an event is a touch event. */
11051105
function isTouchEvent(event: MouseEvent | TouchEvent): event is TouchEvent {
1106-
return event.type.startsWith('touch');
1106+
// This function is called for every pixel that the user has dragged so we need it to be
1107+
// as fast as possible. Since we only bind mouse events and touch events, we can assume
1108+
// that if the event's name starts with `t`, it's a touch event.
1109+
return event.type[0] === 't';
11071110
}
11081111

11091112
/** Gets the element into which the drag preview should be inserted. */

0 commit comments

Comments
 (0)