Changeset 242932 in webkit


Ignore:
Timestamp:
Mar 13, 2019 7:46:16 PM (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-13
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

    r242918 r242932  
     12019-03-13  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-13  Keith Rollin  <krollin@apple.com>
    219
  • trunk/Source/WTF/wtf/IteratorRange.h

    r242706 r242932  
    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

    r242905 r242932  
     12019-03-13  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-13  Chris Dumez  <cdumez@apple.com>
    215
  • trunk/Tools/TestWebKitAPI/CMakeLists.txt

    r242706 r242932  
    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

    r242823 r242932  
    608608                7CCE7F2F1A411B1000447C4C /* WKBrowsingContextLoadDelegateTest.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC3C4C7014575B6A0025FB62 /* WKBrowsingContextLoadDelegateTest.mm */; };
    609609                7CD4C26E1E2C0E6E00929470 /* StringConcatenate.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CD4C26C1E2C0E6E00929470 /* StringConcatenate.cpp */; };
     610                7CEB62AB223609DE0069CBB0 /* IteratorRange.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CEB62A92236086C0069CBB0 /* IteratorRange.cpp */; };
    610611                7CEFA9661AC0B9E200B910FD /* _WKUserContentExtensionStore.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7CEFA9641AC0B9E200B910FD /* _WKUserContentExtensionStore.mm */; };
    611612                7CFBCAE51743238F00B2BFCF /* WillLoad_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CFBCAE31743238E00B2BFCF /* WillLoad_Bundle.cpp */; };
     
    18211822                7CD0D5AA1D5534DE000CC9E1 /* Variant.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Variant.cpp; sourceTree = "<group>"; };
    18221823                7CD4C26C1E2C0E6E00929470 /* StringConcatenate.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StringConcatenate.cpp; sourceTree = "<group>"; };
     1824                7CEB62A92236086C0069CBB0 /* IteratorRange.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = IteratorRange.cpp; sourceTree = "<group>"; };
    18231825                7CEFA9641AC0B9E200B910FD /* _WKUserContentExtensionStore.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = _WKUserContentExtensionStore.mm; sourceTree = "<group>"; };
    18241826                7CFBCADD1743234F00B2BFCF /* WillLoad.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WillLoad.cpp; sourceTree = "<group>"; };
     
    32473249                                26B2DFF815BDE599004F691D /* HashSet.cpp */,
    32483250                                266FAFD215E5775200F61D5B /* IntegerToStringConversion.cpp */,
     3251                                7CEB62A92236086C0069CBB0 /* IteratorRange.cpp */,
    32493252                                7A0509401FB9F04400B33FB8 /* JSONValue.cpp */,
    32503253                                531C1D8D1DF8EF72006E979F /* LEBDecoder.cpp */,
     
    38593862                                7C83DED41D0A590C00FEBCF3 /* HashSet.cpp in Sources */,
    38603863                                7C83DEE01D0A590C00FEBCF3 /* IntegerToStringConversion.cpp in Sources */,
     3864                                7CEB62AB223609DE0069CBB0 /* IteratorRange.cpp in Sources */,
    38613865                                7A0509411FB9F06400B33FB8 /* JSONValue.cpp in Sources */,
    38623866                                531C1D8E1DF8EF72006E979F /* LEBDecoder.cpp in Sources */,
Note: See TracChangeset for help on using the changeset viewer.