Changeset 242702 in webkit


Ignore:
Timestamp:
Mar 11, 2019 8:25:08 AM (5 years ago)
Author:
commit-queue@webkit.org
Message:

Add utility function to allow easy reverse range-based iteration of a container
https://bugs.webkit.org/show_bug.cgi?id=195542

Patch by Sam Weinig <sam@webkit.org> on 2019-03-11
Reviewed by Antti Koivisto.

Source/WTF:

Add functions to create an IteratorRange<T> that will iterate a container backwards. It
works with any container that is compatible with std::rbegin() and std::rend(). It is
expected to be used in conjunction with range-based for-loops like so:

for (auto& value : WTF::makeReversedRange(myContainer))

...

  • wtf/IteratorRange.h:

(WTF::makeReversedRange):

Tools:

  • TestWebKitAPI/CMakeLists.txt:
  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • TestWebKitAPI/Tests/WTF/IteratorRange.cpp: Added.

(TestWebKitAPI::TEST):
Add test to ensure WTF::makeReversedRange() works correctly and uses the correct types.

Location:
trunk
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r242694 r242702  
     12019-03-11  Sam Weinig  <sam@webkit.org>
     2
     3        Add utility function to allow easy reverse range-based iteration of a container
     4        https://bugs.webkit.org/show_bug.cgi?id=195542
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Add functions to create an IteratorRange<T> that will iterate a container backwards. It
     9        works with any container that is compatible with std::rbegin() and std::rend(). It is
     10        expected to be used in conjunction with range-based for-loops like so:
     11
     12        for (auto& value : WTF::makeReversedRange(myContainer))
     13            ...
     14
     15        * wtf/IteratorRange.h:
     16        (WTF::makeReversedRange):
     17
    1182019-03-10  Yusuke Suzuki <utatane.tea@gmail.com> and Fujii Hironori  <Hironori.Fujii@sony.com>
    219
  • trunk/Source/WTF/wtf/IteratorRange.h

    r237099 r242702  
    2626#pragma once
    2727
     28#include <iterator>
     29
    2830namespace WTF {
    2931
     
    4951{
    5052    return IteratorRange<Iterator>(std::forward<Iterator>(begin), std::forward<Iterator>(end));
     53}
     54
     55template<typename Container>
     56IteratorRange<typename Container::reverse_iterator> makeReversedRange(Container& container)
     57{
     58    return makeIteratorRange(std::rbegin(container), std::rend(container));
     59}
     60
     61template<typename Container>
     62IteratorRange<typename Container::const_reverse_iterator> makeReversedRange(const Container& container)
     63{
     64    return makeIteratorRange(std::crbegin(container), std::crend(container));
    5165}
    5266
  • trunk/Tools/ChangeLog

    r242698 r242702  
     12019-03-11  Sam Weinig  <sam@webkit.org>
     2
     3        Add utility function to allow easy reverse range-based iteration of a container
     4        https://bugs.webkit.org/show_bug.cgi?id=195542
     5
     6        Reviewed by Antti Koivisto.
     7
     8        * TestWebKitAPI/CMakeLists.txt:
     9        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     10        * TestWebKitAPI/Tests/WTF/IteratorRange.cpp: Added.
     11        (TestWebKitAPI::TEST):
     12        Add test to ensure WTF::makeReversedRange() works correctly and uses the correct types.
     13
    1142019-03-10  Alex Christensen  <achristensen@webkit.org>
    215
  • trunk/Tools/TestWebKitAPI/CMakeLists.txt

    r242694 r242702  
    130130    ${TESTWEBKITAPI_DIR}/Tests/WTF/Hasher.cpp
    131131    ${TESTWEBKITAPI_DIR}/Tests/WTF/IntegerToStringConversion.cpp
     132    ${TESTWEBKITAPI_DIR}/Tests/WTF/IteratorRange.cpp
    132133    ${TESTWEBKITAPI_DIR}/Tests/WTF/JSONValue.cpp
    133134    ${TESTWEBKITAPI_DIR}/Tests/WTF/LEBDecoder.cpp
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r242696 r242702  
    607607                7CCE7F2F1A411B1000447C4C /* WKBrowsingContextLoadDelegateTest.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC3C4C7014575B6A0025FB62 /* WKBrowsingContextLoadDelegateTest.mm */; };
    608608                7CD4C26E1E2C0E6E00929470 /* StringConcatenate.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CD4C26C1E2C0E6E00929470 /* StringConcatenate.cpp */; };
     609                7CEB62AB223609DE0069CBB0 /* IteratorRange.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CEB62A92236086C0069CBB0 /* IteratorRange.cpp */; };
    609610                7CEFA9661AC0B9E200B910FD /* _WKUserContentExtensionStore.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7CEFA9641AC0B9E200B910FD /* _WKUserContentExtensionStore.mm */; };
    610611                7CFBCAE51743238F00B2BFCF /* WillLoad_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CFBCAE31743238E00B2BFCF /* WillLoad_Bundle.cpp */; };
     
    18191820                7CD0D5AA1D5534DE000CC9E1 /* Variant.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Variant.cpp; sourceTree = "<group>"; };
    18201821                7CD4C26C1E2C0E6E00929470 /* StringConcatenate.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StringConcatenate.cpp; sourceTree = "<group>"; };
     1822                7CEB62A92236086C0069CBB0 /* IteratorRange.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = IteratorRange.cpp; sourceTree = "<group>"; };
    18211823                7CEFA9641AC0B9E200B910FD /* _WKUserContentExtensionStore.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = _WKUserContentExtensionStore.mm; sourceTree = "<group>"; };
    18221824                7CFBCADD1743234F00B2BFCF /* WillLoad.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WillLoad.cpp; sourceTree = "<group>"; };
     
    32443246                                26B2DFF815BDE599004F691D /* HashSet.cpp */,
    32453247                                266FAFD215E5775200F61D5B /* IntegerToStringConversion.cpp */,
     3248                                7CEB62A92236086C0069CBB0 /* IteratorRange.cpp */,
    32463249                                7A0509401FB9F04400B33FB8 /* JSONValue.cpp */,
    32473250                                531C1D8D1DF8EF72006E979F /* LEBDecoder.cpp */,
     
    38563859                                7C83DED41D0A590C00FEBCF3 /* HashSet.cpp in Sources */,
    38573860                                7C83DEE01D0A590C00FEBCF3 /* IntegerToStringConversion.cpp in Sources */,
     3861                                7CEB62AB223609DE0069CBB0 /* IteratorRange.cpp in Sources */,
    38583862                                7A0509411FB9F06400B33FB8 /* JSONValue.cpp in Sources */,
    38593863                                531C1D8E1DF8EF72006E979F /* LEBDecoder.cpp in Sources */,
Note: See TracChangeset for help on using the changeset viewer.