Changeset 179850 in webkit
- Timestamp:
- Feb 9, 2015, 3:39:41 PM (12 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 3 edited
-
ChangeLog (modified) (1 diff)
-
platform/graphics/DisplayRefreshMonitorManager.cpp (modified) (3 diffs)
-
platform/graphics/DisplayRefreshMonitorManager.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r179843 r179850 1 2015-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 1 22 2015-02-09 Jer Noble <jer.noble@apple.com> 2 23 -
trunk/Source/WebCore/platform/graphics/DisplayRefreshMonitorManager.cpp
r169299 r179850 47 47 DisplayRefreshMonitor* DisplayRefreshMonitorManager::ensureMonitorForClient(DisplayRefreshMonitorClient* client) 48 48 { 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; 52 53 monitor->addClient(client); 53 DisplayRefreshMonitor* result = monitor.get(); 54 m_monitors.add(client->displayID(), monitor.release()); 55 return result; 54 return monitor.get(); 56 55 } 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; 59 62 } 60 63 … … 72 75 return; 73 76 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 } 76 86 return; 77 78 DisplayRefreshMonitor* monitor = it->value.get();79 if (monitor->removeClient(client)) {80 if (!monitor->hasClients())81 m_monitors.remove(it);82 87 } 83 88 } … … 96 101 void DisplayRefreshMonitorManager::displayDidRefresh(DisplayRefreshMonitor* monitor) 97 102 { 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); 102 109 } 103 110 -
trunk/Source/WebCore/platform/graphics/DisplayRefreshMonitorManager.h
r169299 r179850 31 31 #include "DisplayRefreshMonitor.h" 32 32 #include "PlatformScreen.h" 33 #include <wtf/HashMap.h>34 33 #include <wtf/NeverDestroyed.h> 35 34 #include <wtf/RefPtr.h> 35 #include <wtf/Vector.h> 36 36 37 37 namespace WebCore { … … 57 57 DisplayRefreshMonitor* ensureMonitorForClient(DisplayRefreshMonitorClient*); 58 58 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; 64 60 }; 65 61
Note:
See TracChangeset
for help on using the changeset viewer.