Closed Bug 1609603 Opened 6 years ago Closed 6 years ago

Optimize callers of `DataTransfer::GetTypes()`

Categories

(Core :: DOM: Copy & Paste and Drag & Drop, task)

task
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla74
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.

https://searchfox.org/mozilla-central/rev/c7b673f443407a359cc0766fb5a4ac323a1d2628/editor/libeditor/EditorEventListener.cpp#862-873

  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.

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.

Pushed by masayuki@d-toybox.com: https://hg.mozilla.org/integration/autoland/rev/00b85432acb8 Optimize the callers of `DataTransfer::GetTypes()` r=smaug
Status: ASSIGNED → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla74
Regressions: 1623239
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: