Skip to content

Commit b15a7ec

Browse files
crisbetojelbourn
authored andcommitted
perf(drag-drop): use narrower check for touch events (#16082)
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 4002140 commit b15a7ec

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
@@ -1113,7 +1113,10 @@ function removeElement(element: HTMLElement | null) {
11131113

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

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

0 commit comments

Comments
 (0)