Changeset 235852 in webkit
- Timestamp:
- Sep 10, 2018 11:19:09 AM (6 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r235841 r235852 1 2018-09-10 Yusuke Suzuki <yusukesuzuki@slowstart.org> 2 3 [WTF] Add Markable<T, Traits> 4 https://bugs.webkit.org/show_bug.cgi?id=189231 5 6 Reviewed by Sam Weinig. 7 8 We can represent a value with nullopt by using std::optional<T>. However, std::optional<T> has storage efficiency 9 problem. It always has a bool indicating that the value is nullopt or not. If we have a following class, 10 11 class A { 12 std::optional<WallTime> m_timeA; 13 std::optional<WallTime> m_timeB; 14 std::optional<WallTime> m_timeC; 15 }; 16 17 This class has significant amount of padding between m_timeA / m_timeB, m_timeB / m_timeC due to the above bool. 18 19 If we know that WallTime has a value that represents invalid, we can use it instead and save the storage. 20 This is very similar problem to our HashTable implementation. In our HashTable implementation, we need Deleted 21 and Empty value, which can represent Deleted and Empty values without sacrificing storage efficiency. 22 23 We should have similar mechanism here. In this patch, we have WTF::Markable<T, Traits>. Traits offers 24 `Traits::isEmptyValue(value)` and `Traits::emptyValue()`. Then, we use this empty value instead of having bool 25 flag. This way, we can make `sizeof(WTF::Markable<T>) == sizeof(T)`. 26 27 This idea is inspired from https://github.com/akrzemi1/markable. But we would like to have WTF::Markable<T> 28 here instead of importing it since we would like to have (1) integrated interfaces with std::optional<T> and (2) 29 aligned function names to HashTraits' `isEmptyValue` and `emptyValue`. 30 31 * WTF.xcodeproj/project.pbxproj: 32 * wtf/CMakeLists.txt: 33 * wtf/Markable.h: Added. 34 (WTF::std::underlying_type<EnumType>::type>::max): EnumMarkableTraits can be used as an MarkableTraits for enum 35 values. We can specify a constant value as an empty value. 36 (WTF::IntegralMarkableTraits::isEmptyValue): 37 (WTF::IntegralMarkableTraits::emptyValue): IntegralMarkableTraits can be used as an MarkableTraits for integral 38 types including int etc. 39 (WTF::Markable::Markable): 40 (WTF::Markable::operator bool const): 41 (WTF::Markable::reset): 42 (WTF::Markable::value const): 43 (WTF::Markable::value): 44 (WTF::Markable::operator-> const): 45 (WTF::Markable::operator->): 46 (WTF::Markable::operator* const): 47 (WTF::Markable::operator*): 48 (WTF::Markable::operator std::optional<T>): 49 (WTF::Markable::operator std::optional<T> const): This operator allows us to cast Markable<T> to 50 std::optional<T>. 51 * wtf/MonotonicTime.h: 52 (WTF::MonotonicTime::MarkableTraits::isEmptyValue): 53 (WTF::MonotonicTime::MarkableTraits::emptyValue): MarkableTraits for MonotonicTime. MonotonicTime::nan() is used 54 as an empty value. 55 * wtf/Seconds.h: 56 (WTF::Seconds::MarkableTraits::isEmptyValue): 57 (WTF::Seconds::MarkableTraits::emptyValue): MarkableTraits for Seconds. Seconds::nan() is used as an empty value. 58 * wtf/WallTime.h: 59 (WTF::WallTime::nan): 60 (WTF::WallTime::MarkableTraits::isEmptyValue): 61 (WTF::WallTime::MarkableTraits::emptyValue): MarkableTraits for WallTime. WallTime::nan() is used as an empty value. 62 1 63 2018-09-09 Fujii Hironori <Hironori.Fujii@sony.com> 2 64 -
trunk/Source/WTF/WTF.xcodeproj/project.pbxproj
r235547 r235852 633 633 E3A32BC21FC830E2007D7E76 /* JSValueMalloc.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSValueMalloc.cpp; sourceTree = "<group>"; }; 634 634 E3A32BC31FC830E2007D7E76 /* JSValueMalloc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSValueMalloc.h; sourceTree = "<group>"; }; 635 304CA4E41375437EBE931D03 /* Markable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Markable.h; sourceTree = "<group>"; }; 635 636 E3CF76902115D6BA0091DE48 /* CompactPointerTuple.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CompactPointerTuple.h; sourceTree = "<group>"; }; 636 637 E3E158251EADA53C004A079D /* SystemFree.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SystemFree.h; sourceTree = "<group>"; }; … … 965 966 A8A472C7151A825B004123FF /* MainThread.h */, 966 967 1A233C7C17DAA6E300A93ACF /* MallocPtr.h */, 968 304CA4E41375437EBE931D03 /* Markable.h */, 967 969 A8A472C9151A825B004123FF /* MathExtras.h */, 968 970 1447AEC818FCE59400B3D7FF /* mbmalloc.cpp */, -
trunk/Source/WTF/wtf/CMakeLists.txt
r235547 r235852 123 123 MainThread.h 124 124 MallocPtr.h 125 Markable.h 125 126 MathExtras.h 126 127 MediaTime.h -
trunk/Source/WTF/wtf/MonotonicTime.h
r229174 r235852 166 166 } 167 167 168 struct MarkableTraits; 169 168 170 private: 169 171 constexpr MonotonicTime(double rawValue) … … 173 175 174 176 double m_value { 0 }; 177 }; 178 179 struct MonotonicTime::MarkableTraits { 180 static bool isEmptyValue(MonotonicTime time) 181 { 182 return std::isnan(time.m_value); 183 } 184 185 static constexpr MonotonicTime emptyValue() 186 { 187 return MonotonicTime::nan(); 188 } 175 189 }; 176 190 -
trunk/Source/WTF/wtf/Seconds.h
r229209 r235852 248 248 } 249 249 250 struct MarkableTraits; 251 250 252 private: 251 253 double m_value { 0 }; … … 254 256 WTF_EXPORT_PRIVATE void sleep(Seconds); 255 257 258 struct Seconds::MarkableTraits { 259 static bool isEmptyValue(Seconds seconds) 260 { 261 return std::isnan(seconds.value()); 262 } 263 264 static constexpr Seconds emptyValue() 265 { 266 return Seconds::nan(); 267 } 268 }; 269 256 270 inline namespace seconds_literals { 257 271 -
trunk/Source/WTF/wtf/WallTime.h
r228942 r235852 57 57 58 58 static constexpr WallTime infinity() { return fromRawSeconds(std::numeric_limits<double>::infinity()); } 59 static constexpr WallTime nan() { return fromRawSeconds(std::numeric_limits<double>::quiet_NaN()); } 59 60 60 61 constexpr Seconds secondsSinceEpoch() const { return Seconds(m_value); } … … 133 134 return *this; 134 135 } 136 137 struct MarkableTraits; 138 135 139 private: 136 140 constexpr WallTime(double rawValue) … … 140 144 141 145 double m_value { 0 }; 146 }; 147 148 struct WallTime::MarkableTraits { 149 static bool isEmptyValue(WallTime time) 150 { 151 return std::isnan(time.m_value); 152 } 153 154 static constexpr WallTime emptyValue() 155 { 156 return WallTime::nan(); 157 } 142 158 }; 143 159 -
trunk/Source/WebCore/ChangeLog
r235850 r235852 1 2018-09-10 Yusuke Suzuki <yusukesuzuki@slowstart.org> 2 3 [WTF] Add Markable<T, Traits> 4 https://bugs.webkit.org/show_bug.cgi?id=189231 5 6 Reviewed by Sam Weinig. 7 8 Use Markable<Seconds> and Markable<WallTime> in ResourceResponseBase. 9 Since these fields are parsed results from http header fields, Seconds::nan() and WallTime::nan() 10 can be used as an empty value for these fields. Thus we can use Markable because it uses 11 these nan values as an empty values (they are configured by Seconds::MarkableTraits and WallTime::MarkableTraits). 12 This reduces the size of ResourceResponseBase from 448 to 416. 13 14 * platform/network/ResourceResponseBase.h: 15 1 16 2018-09-07 Matt Rajca <mrajca@apple.com> 2 17 -
trunk/Source/WebCore/platform/network/ResourceResponseBase.h
r234422 r235852 33 33 #include "ParsedContentRange.h" 34 34 #include "URL.h" 35 #include <wtf/Markable.h> 35 36 #include <wtf/WallTime.h> 36 37 … … 215 216 216 217 private: 217 mutable std::optional<Seconds> m_age;218 mutable std::optional<WallTime> m_date;219 mutable std::optional<WallTime> m_expires;220 mutable std::optional<WallTime> m_lastModified;218 mutable Markable<Seconds, Seconds::MarkableTraits> m_age; 219 mutable Markable<WallTime, WallTime::MarkableTraits> m_date; 220 mutable Markable<WallTime, WallTime::MarkableTraits> m_expires; 221 mutable Markable<WallTime, WallTime::MarkableTraits> m_lastModified; 221 222 mutable ParsedContentRange m_contentRange; 222 223 mutable CacheControlDirectives m_cacheControlDirectives; -
trunk/Tools/ChangeLog
r235851 r235852 1 2018-09-10 Yusuke Suzuki <yusukesuzuki@slowstart.org> 2 3 [WTF] Add Markable<T, Traits> 4 https://bugs.webkit.org/show_bug.cgi?id=189231 5 6 Reviewed by Sam Weinig. 7 8 Add tests for Markable. 9 10 * TestWebKitAPI/CMakeLists.txt: 11 * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: 12 * TestWebKitAPI/Tests/WTF/Markable.cpp: Added. 13 (TestWebKitAPI::TEST): 14 1 15 2018-09-10 Simon Fraser <simon.fraser@apple.com> 2 16 -
trunk/Tools/TestWebKitAPI/CMakeLists.txt
r235718 r235852 124 124 ${TESTWEBKITAPI_DIR}/Tests/WTF/Logger.cpp 125 125 ${TESTWEBKITAPI_DIR}/Tests/WTF/MD5.cpp 126 ${TESTWEBKITAPI_DIR}/Tests/WTF/Markable.cpp 126 127 ${TESTWEBKITAPI_DIR}/Tests/WTF/MathExtras.cpp 127 128 ${TESTWEBKITAPI_DIR}/Tests/WTF/MediaTime.cpp -
trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
r235850 r235852 42 42 0F2C20B81DCD545000542D9E /* Time.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F2C20B71DCD544800542D9E /* Time.cpp */; }; 43 43 0F30CB5C1FCE1796004B5323 /* ConcurrentPtrHashSet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F30CB5B1FCE1792004B5323 /* ConcurrentPtrHashSet.cpp */; }; 44 4909EE3A2D09480C88982D56 /* Markable.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EC79F168BE454E579E417B05 /* Markable.cpp */; }; 44 45 0F3B94A71A77267400DE3272 /* WKWebViewEvaluateJavaScript.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0F3B94A51A77266C00DE3272 /* WKWebViewEvaluateJavaScript.mm */; }; 45 46 0F4FFA9E1ED3AA8500F7111F /* SnapshotViaRenderInContext.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0F4FFA9D1ED3AA8500F7111F /* SnapshotViaRenderInContext.mm */; }; … … 1237 1238 0F2C20B71DCD544800542D9E /* Time.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Time.cpp; sourceTree = "<group>"; }; 1238 1239 0F30CB5B1FCE1792004B5323 /* ConcurrentPtrHashSet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ConcurrentPtrHashSet.cpp; sourceTree = "<group>"; }; 1240 EC79F168BE454E579E417B05 /* Markable.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Markable.cpp; sourceTree = "<group>"; }; 1239 1241 0F3B94A51A77266C00DE3272 /* WKWebViewEvaluateJavaScript.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewEvaluateJavaScript.mm; sourceTree = "<group>"; }; 1240 1242 0F4FFA9D1ED3AA8500F7111F /* SnapshotViaRenderInContext.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SnapshotViaRenderInContext.mm; sourceTree = "<group>"; }; … … 3015 3017 A57D54F41F3395D000A97AA7 /* Logger.cpp */, 3016 3018 A57D54F51F3395D000A97AA7 /* Logger.h */, 3019 EC79F168BE454E579E417B05 /* Markable.cpp */, 3017 3020 B4039F9C15E6D8B3007255D6 /* MathExtras.cpp */, 3018 3021 CD5393C71757BA9700C07123 /* MD5.cpp */, … … 3600 3603 7C83DF1D1D0A590C00FEBCF3 /* Lock.cpp in Sources */, 3601 3604 A57D54F61F3395D000A97AA7 /* Logger.cpp in Sources */, 3605 4909EE3A2D09480C88982D56 /* Markable.cpp in Sources */, 3602 3606 7C83DEED1D0A590C00FEBCF3 /* MathExtras.cpp in Sources */, 3603 3607 7C83DEEF1D0A590C00FEBCF3 /* MD5.cpp in Sources */,
Note: See TracChangeset
for help on using the changeset viewer.