Optimize callers of `DataTransfer::GetTypes()`
Categories
(Core :: DOM: Copy & Paste and Drag & Drop, task)
Tracking
()
Tracking | Status | |
---|---|---|
firefox74 | --- | fixed |
People
(Reporter: masayuki, Assigned: masayuki)
References
Details
Attachments
(1 file)
EditorEventListener
checks whether dragging data is acceptable or not at every dragstart
, dragenter
, dragover
and drop
events. Especially for dragover
, this terribly wastes runtime cost.
nsTArray<nsString> types;
dataTransfer->GetTypes(types, CallerType::System);
// Plaintext editors only support dropping text. Otherwise, HTML and files
// can be dropped as well.
if (!types.Contains(NS_LITERAL_STRING(kTextMime)) &&
!types.Contains(NS_LITERAL_STRING(kMozTextInternal)) &&
(editorBase->IsPlaintextEditor() ||
(!types.Contains(NS_LITERAL_STRING(kHTMLMime)) &&
!types.Contains(NS_LITERAL_STRING(kFileMime))))) {
return false;
}
First, it gets all types which the data transfer has. At this time, types.AppendElement()
is called a lot (i.e., reallocation may run multiple times) and also retrieves types of all items even if looking for a first item.
Thus, with implementing HasType()
, we can stop doing unnecessary jobs.
Assignee | ||
Comment 1•6 years ago
|
||
In C++ code, DataTransfer::GetTypes()
are used for checking whether the
DataTransfer
instance has specific type DataTransferItem
or not. Therefore,
it does not make sense to retrieve all item types nor compare some types
looking for with the retrieved item types.
This patch adds DataTransfer::HasType()
and DataTransfer::HasFile()
for
the current C++ users. They don't take CallerType
since all C++ users use
GetTypes()
as CallertType::System
. And they just call a corresponding
method of DataTransferItemList
.
Then, DataTransferItemList
methods compares given type with every items
simply.
Note that this patch moves DataTransfer::GetTypes()
to DataTransferItemList
too because new methods and GetTypes()
should be maintained at every logic
changes.
The reason why there is no DataTransfer::HasAnyOfTypes()
method is,
DataTransfer.h
cannot include DataTransferItemList.h
due to their
dependency but parameter pack requires inline methods.
Comment 3•6 years ago
|
||
bugherder |
Description
•