Title: [198437] trunk/Tools
Revision
198437
Author
[email protected]
Date
2016-03-18 12:18:52 -0700 (Fri, 18 Mar 2016)

Log Message

Add test for HashMap::ensure that shows that moving into the lambda does not incure extra cost
https://bugs.webkit.org/show_bug.cgi?id=155621

Patch by Sam Weinig <[email protected]> on 2016-03-18
Reviewed by Alex Christensen.

* TestWebKitAPI/Tests/WTF/HashMap.cpp:
(TestWebKitAPI::ObjectWithRefLogger::ObjectWithRefLogger):
(TestWebKitAPI::testMovingUsingEnsure):
(TestWebKitAPI::testMovingUsingAdd):
Add tests ensuring that objects moved into a map using ensure don't
have extra ref-churn.

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (198436 => 198437)


--- trunk/Tools/ChangeLog	2016-03-18 19:04:58 UTC (rev 198436)
+++ trunk/Tools/ChangeLog	2016-03-18 19:18:52 UTC (rev 198437)
@@ -1,3 +1,17 @@
+2016-03-18  Sam Weinig  <[email protected]>
+
+        Add test for HashMap::ensure that shows that moving into the lambda does not incure extra cost
+        https://bugs.webkit.org/show_bug.cgi?id=155621
+
+        Reviewed by Alex Christensen.
+
+        * TestWebKitAPI/Tests/WTF/HashMap.cpp:
+        (TestWebKitAPI::ObjectWithRefLogger::ObjectWithRefLogger):
+        (TestWebKitAPI::testMovingUsingEnsure):
+        (TestWebKitAPI::testMovingUsingAdd):
+        Add tests ensuring that objects moved into a map using ensure don't
+        have extra ref-churn.
+
 2016-03-17  Tim Horton  <[email protected]>
 
         Fix some deprecation warnings in WebEditingTester

Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/HashMap.cpp (198436 => 198437)


--- trunk/Tools/TestWebKitAPI/Tests/WTF/HashMap.cpp	2016-03-18 19:04:58 UTC (rev 198436)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/HashMap.cpp	2016-03-18 19:18:52 UTC (rev 198437)
@@ -28,8 +28,10 @@
 #include "Counters.h"
 #include "MoveOnly.h"
 #include "RefLogger.h"
+#include "Test.h"
 #include <string>
 #include <wtf/HashMap.h>
+#include <wtf/Ref.h>
 #include <wtf/text/StringHash.h>
 
 namespace TestWebKitAPI {
@@ -570,4 +572,49 @@
     }
 }
 
+class ObjectWithRefLogger {
+public:
+    ObjectWithRefLogger(Ref<RefLogger>&& logger)
+        : m_logger(WTFMove(logger))
+    {
+    }
+
+    Ref<RefLogger> m_logger;
+};
+
+
+void testMovingUsingEnsure(Ref<RefLogger>&& logger)
+{
+    HashMap<unsigned, std::unique_ptr<ObjectWithRefLogger>> map;
+    
+    map.ensure(1, [&] { return std::make_unique<ObjectWithRefLogger>(WTFMove(logger)); });
+}
+
+void testMovingUsingAdd(Ref<RefLogger>&& logger)
+{
+    HashMap<unsigned, std::unique_ptr<ObjectWithRefLogger>> map;
+
+    auto& slot = map.add(1, nullptr).iterator->value;
+    slot = std::make_unique<ObjectWithRefLogger>(WTFMove(logger));
+}
+
+TEST(WTF_HashMap, Ensure_LambdasCapturingByReference)
+{
+    {
+        DerivedRefLogger a("a");
+        Ref<RefLogger> ref(a);
+        testMovingUsingEnsure(WTFMove(ref));
+
+        EXPECT_STREQ("ref(a) deref(a) ", takeLogStr().c_str());
+    }
+
+    {
+        DerivedRefLogger a("a");
+        Ref<RefLogger> ref(a);
+        testMovingUsingAdd(WTFMove(ref));
+
+        EXPECT_STREQ("ref(a) deref(a) ", takeLogStr().c_str());
+    }
+}
+
 } // namespace TestWebKitAPI
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to