⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 179850 in webkit


Ignore:
Timestamp:
Feb 9, 2015, 3:39:41 PM (12 years ago)
Author:
timothy_horton@apple.com
Message:

Avoid using a HashMap for DisplayRefreshMonitorManager, which rarely has more than one item
https://bugs.webkit.org/show_bug.cgi?id=141353

Reviewed by Anders Carlsson.

No new tests, because there's no behavior change.

  • platform/graphics/DisplayRefreshMonitorManager.cpp:

(WebCore::DisplayRefreshMonitorManager::ensureMonitorForClient):
(WebCore::DisplayRefreshMonitorManager::unregisterClient):
(WebCore::DisplayRefreshMonitorManager::displayDidRefresh):

  • platform/graphics/DisplayRefreshMonitorManager.h:

Use a Vector of RefPtr<DisplayRefreshMonitor> instead of a HashMap
from uint64_t to RefPtr<DisplayRefreshMonitor>. There's usually only one
display, so there's usually only one DisplayRefreshMonitor. Linear search
on the Vector will be faster than the hash lookup in all conceivable cases.
This also avoids the situation mentioned in the comments in DisplayRefreshMonitorManager.h
where we don't know enough about PlatformDisplayID to safely hash it.

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r179843 r179850  
     12015-02-09  Timothy Horton  <timothy_horton@apple.com>
     2
     3        Avoid using a HashMap for DisplayRefreshMonitorManager, which rarely has more than one item
     4        https://bugs.webkit.org/show_bug.cgi?id=141353
     5
     6        Reviewed by Anders Carlsson.
     7
     8        No new tests, because there's no behavior change.
     9
     10        * platform/graphics/DisplayRefreshMonitorManager.cpp:
     11        (WebCore::DisplayRefreshMonitorManager::ensureMonitorForClient):
     12        (WebCore::DisplayRefreshMonitorManager::unregisterClient):
     13        (WebCore::DisplayRefreshMonitorManager::displayDidRefresh):
     14        * platform/graphics/DisplayRefreshMonitorManager.h:
     15        Use a Vector of RefPtr<DisplayRefreshMonitor> instead of a HashMap
     16        from uint64_t to RefPtr<DisplayRefreshMonitor>. There's usually only one
     17        display, so there's usually only one DisplayRefreshMonitor. Linear search
     18        on the Vector will be faster than the hash lookup in all conceivable cases.
     19        This also avoids the situation mentioned in the comments in DisplayRefreshMonitorManager.h
     20        where we don't know enough about PlatformDisplayID to safely hash it.
     21
    1222015-02-09  Jer Noble  <jer.noble@apple.com>
    223
  • trunk/Source/WebCore/platform/graphics/DisplayRefreshMonitorManager.cpp

    r169299 r179850  
    4747DisplayRefreshMonitor* DisplayRefreshMonitorManager::ensureMonitorForClient(DisplayRefreshMonitorClient* client)
    4848{
    49     DisplayRefreshMonitorMap::iterator it = m_monitors.find(client->displayID());
    50     if (it == m_monitors.end()) {
    51         RefPtr<DisplayRefreshMonitor> monitor = DisplayRefreshMonitor::create(client);
     49    PlatformDisplayID clientDisplayID = client->displayID();
     50    for (const RefPtr<DisplayRefreshMonitor>& monitor : m_monitors) {
     51        if (monitor->displayID() != clientDisplayID)
     52            continue;
    5253        monitor->addClient(client);
    53         DisplayRefreshMonitor* result = monitor.get();
    54         m_monitors.add(client->displayID(), monitor.release());
    55         return result;
     54        return monitor.get();
    5655    }
    57     it->value->addClient(client);
    58     return it->value.get();
     56
     57    RefPtr<DisplayRefreshMonitor> monitor = DisplayRefreshMonitor::create(client);
     58    monitor->addClient(client);
     59    DisplayRefreshMonitor* result = monitor.get();
     60    m_monitors.append(monitor.release());
     61    return result;
    5962}
    6063
     
    7275        return;
    7376
    74     DisplayRefreshMonitorMap::iterator it = m_monitors.find(client->displayID());
    75     if (it == m_monitors.end())
     77    PlatformDisplayID clientDisplayID = client->displayID();
     78    for (size_t i = 0; i < m_monitors.size(); ++i) {
     79        RefPtr<DisplayRefreshMonitor> monitor = m_monitors[i];
     80        if (monitor->displayID() != clientDisplayID)
     81            continue;
     82        if (monitor->removeClient(client)) {
     83            if (!monitor->hasClients())
     84                m_monitors.remove(i);
     85        }
    7686        return;
    77 
    78     DisplayRefreshMonitor* monitor = it->value.get();
    79     if (monitor->removeClient(client)) {
    80         if (!monitor->hasClients())
    81             m_monitors.remove(it);
    8287    }
    8388}
     
    96101void DisplayRefreshMonitorManager::displayDidRefresh(DisplayRefreshMonitor* monitor)
    97102{
    98     if (monitor->shouldBeTerminated()) {
    99         ASSERT(m_monitors.contains(monitor->displayID()));
    100         m_monitors.remove(monitor->displayID());
    101     }
     103    if (!monitor->shouldBeTerminated())
     104        return;
     105
     106    size_t monitorIndex = m_monitors.find(monitor);
     107    ASSERT(monitorIndex != notFound);
     108    m_monitors.remove(monitorIndex);
    102109}
    103110
  • trunk/Source/WebCore/platform/graphics/DisplayRefreshMonitorManager.h

    r169299 r179850  
    3131#include "DisplayRefreshMonitor.h"
    3232#include "PlatformScreen.h"
    33 #include <wtf/HashMap.h>
    3433#include <wtf/NeverDestroyed.h>
    3534#include <wtf/RefPtr.h>
     35#include <wtf/Vector.h>
    3636
    3737namespace WebCore {
     
    5757    DisplayRefreshMonitor* ensureMonitorForClient(DisplayRefreshMonitorClient*);
    5858
    59     // We know nothing about the values of PlatformDisplayIDs, so use UnsignedWithZeroKeyHashTraits.
    60     // FIXME: Since we know nothing about these values, this is not sufficient.
    61     // Even with UnsignedWithZeroKeyHashTraits, there are still two special values used for empty and deleted hash table slots.
    62     typedef HashMap<uint64_t, RefPtr<DisplayRefreshMonitor>, WTF::IntHash<uint64_t>, WTF::UnsignedWithZeroKeyHashTraits<uint64_t>> DisplayRefreshMonitorMap;
    63     DisplayRefreshMonitorMap m_monitors;
     59    Vector<RefPtr<DisplayRefreshMonitor>> m_monitors;
    6460};
    6561
Note: See TracChangeset for help on using the changeset viewer.