Changeset 195417 in webkit
- Timestamp:
- Jan 21, 2016 11:54:51 AM (8 years ago)
- Location:
- trunk/Source
- Files:
-
- 5 added
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/CMakeLists.txt
r195407 r195417 121 121 b3/B3DuplicateTails.cpp 122 122 b3/B3Effects.cpp 123 b3/B3EliminateCommonSubexpressions.cpp 123 124 b3/B3FixSSA.cpp 124 125 b3/B3FoldPathConstants.cpp … … 143 144 b3/B3PhiChildren.cpp 144 145 b3/B3Procedure.cpp 146 b3/B3PureCSE.cpp 145 147 b3/B3ReduceDoubleToFloat.cpp 146 148 b3/B3ReduceStrength.cpp -
trunk/Source/JavaScriptCore/ChangeLog
r195416 r195417 1 2016-01-21 Filip Pizlo <fpizlo@apple.com> 2 3 B3 should have load elimination 4 https://bugs.webkit.org/show_bug.cgi?id=153288 5 6 Reviewed by Geoffrey Garen. 7 8 This adds a complete GCSE pass that includes load elimination. It would have been super hard 9 to make this work as part of the reduceStrength() fixpoint, since GCSE needs to analyze 10 control flow and reduceStrength() is messing with control flow. So, I did a compromise: I 11 factored out the pure CSE that reduceStrength() was already doing, and now we have: 12 13 - reduceStrength() still does pure CSE using the new PureCSE helper. 14 15 - eliminateCommonSubexpressions() is a separate phase that does general CSE. It uses the 16 PureCSE helper for pure values and does its own special thing for memory values. 17 18 Unfortunately, this doesn't help any benchmark right now. It doesn't hurt anything, either, 19 and it's likely to become a bigger pay-off once we implement other features, like mapping 20 FTL's abstract heaps onto B3's heap ranges. 21 22 * CMakeLists.txt: 23 * JavaScriptCore.xcodeproj/project.pbxproj: 24 * b3/B3EliminateCommonSubexpressions.cpp: Added. 25 (JSC::B3::eliminateCommonSubexpressions): 26 * b3/B3EliminateCommonSubexpressions.h: Added. 27 * b3/B3Generate.cpp: 28 (JSC::B3::generateToAir): 29 * b3/B3HeapRange.h: 30 (JSC::B3::HeapRange::HeapRange): 31 * b3/B3InsertionSet.h: 32 (JSC::B3::InsertionSet::InsertionSet): 33 (JSC::B3::InsertionSet::isEmpty): 34 (JSC::B3::InsertionSet::code): 35 (JSC::B3::InsertionSet::appendInsertion): 36 * b3/B3MemoryValue.h: 37 * b3/B3PureCSE.cpp: Added. 38 (JSC::B3::PureCSE::PureCSE): 39 (JSC::B3::PureCSE::~PureCSE): 40 (JSC::B3::PureCSE::clear): 41 (JSC::B3::PureCSE::process): 42 * b3/B3PureCSE.h: Added. 43 * b3/B3ReduceStrength.cpp: 44 * b3/B3ReduceStrength.h: 45 * b3/B3Validate.cpp: 46 1 47 2016-01-21 Keith Miller <keith_miller@apple.com> 2 48 -
trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
r195395 r195417 468 468 0F714CA416EA92F000F3EBEB /* DFGBackwardsPropagationPhase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F714CA116EA92ED00F3EBEB /* DFGBackwardsPropagationPhase.cpp */; }; 469 469 0F714CA516EA92F200F3EBEB /* DFGBackwardsPropagationPhase.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F714CA216EA92ED00F3EBEB /* DFGBackwardsPropagationPhase.h */; }; 470 0F725CA71C503DED00AD943A /* B3EliminateCommonSubexpressions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F725CA31C503DED00AD943A /* B3EliminateCommonSubexpressions.cpp */; }; 471 0F725CA81C503DED00AD943A /* B3EliminateCommonSubexpressions.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F725CA41C503DED00AD943A /* B3EliminateCommonSubexpressions.h */; }; 472 0F725CA91C503DED00AD943A /* B3PureCSE.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F725CA51C503DED00AD943A /* B3PureCSE.cpp */; }; 473 0F725CAA1C503DED00AD943A /* B3PureCSE.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F725CA61C503DED00AD943A /* B3PureCSE.h */; }; 470 474 0F725CAF1C506D3B00AD943A /* B3FoldPathConstants.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F725CAD1C506D3B00AD943A /* B3FoldPathConstants.cpp */; }; 471 475 0F725CB01C506D3B00AD943A /* B3FoldPathConstants.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F725CAE1C506D3B00AD943A /* B3FoldPathConstants.h */; }; … … 2648 2652 0F714CA116EA92ED00F3EBEB /* DFGBackwardsPropagationPhase.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DFGBackwardsPropagationPhase.cpp; path = dfg/DFGBackwardsPropagationPhase.cpp; sourceTree = "<group>"; }; 2649 2653 0F714CA216EA92ED00F3EBEB /* DFGBackwardsPropagationPhase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DFGBackwardsPropagationPhase.h; path = dfg/DFGBackwardsPropagationPhase.h; sourceTree = "<group>"; }; 2654 0F725CA31C503DED00AD943A /* B3EliminateCommonSubexpressions.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = B3EliminateCommonSubexpressions.cpp; path = b3/B3EliminateCommonSubexpressions.cpp; sourceTree = "<group>"; }; 2655 0F725CA41C503DED00AD943A /* B3EliminateCommonSubexpressions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = B3EliminateCommonSubexpressions.h; path = b3/B3EliminateCommonSubexpressions.h; sourceTree = "<group>"; }; 2656 0F725CA51C503DED00AD943A /* B3PureCSE.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = B3PureCSE.cpp; path = b3/B3PureCSE.cpp; sourceTree = "<group>"; }; 2657 0F725CA61C503DED00AD943A /* B3PureCSE.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = B3PureCSE.h; path = b3/B3PureCSE.h; sourceTree = "<group>"; }; 2650 2658 0F725CAD1C506D3B00AD943A /* B3FoldPathConstants.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = B3FoldPathConstants.cpp; path = b3/B3FoldPathConstants.cpp; sourceTree = "<group>"; }; 2651 2659 0F725CAE1C506D3B00AD943A /* B3FoldPathConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = B3FoldPathConstants.h; path = b3/B3FoldPathConstants.h; sourceTree = "<group>"; }; … … 4784 4792 0FEC85C41BE16F5A0080FF74 /* B3Effects.cpp */, 4785 4793 0FEC85BE1BE167A00080FF74 /* B3Effects.h */, 4794 0F725CA31C503DED00AD943A /* B3EliminateCommonSubexpressions.cpp */, 4795 0F725CA41C503DED00AD943A /* B3EliminateCommonSubexpressions.h */, 4786 4796 0F6B8AE01C4EFE1700969052 /* B3FixSSA.cpp */, 4787 4797 0F6B8AE11C4EFE1700969052 /* B3FixSSA.h */, … … 4835 4845 0FEC84E21BDACDAC0080FF74 /* B3Procedure.h */, 4836 4846 0FEC84E31BDACDAC0080FF74 /* B3ProcedureInlines.h */, 4847 0F725CA51C503DED00AD943A /* B3PureCSE.cpp */, 4848 0F725CA61C503DED00AD943A /* B3PureCSE.h */, 4837 4849 43422A641C16221E00E2EB98 /* B3ReduceDoubleToFloat.cpp */, 4838 4850 43422A651C16221E00E2EB98 /* B3ReduceDoubleToFloat.h */, … … 7325 7337 0FEA0A34170D40BF00BB722C /* DFGJITCode.h in Headers */, 7326 7338 86EC9DCC1328DF82002B2AD7 /* DFGJITCompiler.h in Headers */, 7339 0F725CA81C503DED00AD943A /* B3EliminateCommonSubexpressions.h in Headers */, 7327 7340 A78A9779179738B8009DF744 /* DFGJITFinalizer.h in Headers */, 7328 7341 0FC97F4018202119002C9B26 /* DFGJumpReplacement.h in Headers */, … … 7652 7665 A1D792FF1B43864B004516F5 /* IntlNumberFormatConstructor.h in Headers */, 7653 7666 A125846E1B45A36000CC7F6C /* IntlNumberFormatConstructor.lut.h in Headers */, 7667 0F725CAA1C503DED00AD943A /* B3PureCSE.h in Headers */, 7654 7668 A1D793011B43864B004516F5 /* IntlNumberFormatPrototype.h in Headers */, 7655 7669 A125846F1B45A36000CC7F6C /* IntlNumberFormatPrototype.lut.h in Headers */, … … 8881 8895 0F666EC61835672B00D017F1 /* DFGAvailability.cpp in Sources */, 8882 8896 0F2B9CE219D0BA7D00B1D1B5 /* DFGAvailabilityMap.cpp in Sources */, 8897 0F725CA71C503DED00AD943A /* B3EliminateCommonSubexpressions.cpp in Sources */, 8883 8898 0F714CA416EA92F000F3EBEB /* DFGBackwardsPropagationPhase.cpp in Sources */, 8884 8899 A7D89CF217A0B8CC00773AD8 /* DFGBasicBlock.cpp in Sources */, … … 9329 9344 142D6F1113539A4100B02E86 /* MarkStack.cpp in Sources */, 9330 9345 70B791981C024A29002481E2 /* GeneratorPrototype.cpp in Sources */, 9346 0F725CA91C503DED00AD943A /* B3PureCSE.cpp in Sources */, 9331 9347 4340A4841A9051AF00D73CCA /* MathCommon.cpp in Sources */, 9332 9348 0F37308C1C0BD29100052BFA /* B3PhiChildren.cpp in Sources */, -
trunk/Source/JavaScriptCore/b3/B3Generate.cpp
r195395 r195417 34 34 #include "B3Common.h" 35 35 #include "B3DuplicateTails.h" 36 #include "B3EliminateCommonSubexpressions.h" 36 37 #include "B3FoldPathConstants.h" 37 38 #include "B3LegalizeMemoryOffsets.h" … … 79 80 reduceDoubleToFloat(procedure); 80 81 reduceStrength(procedure); 82 eliminateCommonSubexpressions(procedure); 81 83 duplicateTails(procedure); 82 84 foldPathConstants(procedure); -
trunk/Source/JavaScriptCore/b3/B3HeapRange.h
r191952 r195417 41 41 class HeapRange { 42 42 public: 43 typedef unsigned Type; 44 43 45 HeapRange() 44 46 : m_begin(0) -
trunk/Source/JavaScriptCore/b3/B3InsertionSet.h
r195395 r195417 49 49 } 50 50 51 bool isEmpty() const { return m_insertions.isEmpty(); } 52 51 53 Procedure& code() { return m_procedure; } 52 54 -
trunk/Source/JavaScriptCore/b3/B3MemoryValue.h
r195395 r195417 60 60 const HeapRange& range() const { return m_range; } 61 61 void setRange(const HeapRange& range) { m_range = range; } 62 63 bool isStore() const { return type() == Void; } 64 bool isLoad() const { return type() != Void; } 62 65 63 66 size_t accessByteSize() const; -
trunk/Source/JavaScriptCore/b3/B3ReduceStrength.cpp
r195395 r195417 39 39 #include "B3PhiChildren.h" 40 40 #include "B3ProcedureInlines.h" 41 #include "B3PureCSE.h" 41 42 #include "B3UpsilonValue.h" 42 43 #include "B3UseCounts.h" … … 283 284 m_proc.resetValueOwners(); 284 285 m_dominators = &m_proc.dominators(); // Recompute if necessary. 285 m_pure Values.clear();286 m_pureCSE.clear(); 286 287 287 288 for (BasicBlock* block : m_proc.blocksInPreOrder()) { … … 1752 1753 void replaceIfRedundant() 1753 1754 { 1754 // This does a very simple pure dominator-based CSE. In the future we could add load elimination. 1755 // Note that if we add load elimination, we should do it by directly matching load and store 1756 // instructions instead of using the ValueKey functionality or doing DFG HeapLocation-like 1757 // things. 1758 1759 // Don't bother with identities. We kill those anyway. 1760 if (m_value->opcode() == Identity) 1761 return; 1762 1763 ValueKey key = m_value->key(); 1764 if (!key) 1765 return; 1766 1767 Vector<Value*, 1>& matches = m_pureValues.add(key, Vector<Value*, 1>()).iterator->value; 1768 1769 // Replace this value with whichever value dominates us. 1770 for (Value* match : matches) { 1771 if (m_dominators->dominates(match->owner, m_value->owner)) { 1772 m_value->replaceWithIdentity(match); 1773 m_changed = true; 1774 return; 1775 } 1776 } 1777 1778 matches.append(m_value); 1755 m_changed |= m_pureCSE.process(m_value, *m_dominators); 1779 1756 } 1780 1757 … … 2043 2020 Value* m_value { nullptr }; 2044 2021 Dominators* m_dominators { nullptr }; 2045 HashMap<ValueKey, Vector<Value*, 1>> m_pureValues;2022 PureCSE m_pureCSE; 2046 2023 bool m_changed { false }; 2047 2024 bool m_changedCFG { false }; -
trunk/Source/JavaScriptCore/b3/B3ReduceStrength.h
r193987 r195417 33 33 class Procedure; 34 34 35 // Does strength reduction, constant folding, canonicalization, CFG simplification, DCE, and CSE. This 36 // phase runs those optimizations to fixpoint. The goal of the phase is to dramatically reduce the 37 // complexity of the code. In the future, it's preferable to add optimizations to this phase rather than 38 // creating new optimizations because then the optimizations can participate in the fixpoint. However, 39 // this phase shouldn't become too expensive, so expensive optimizations should be separate. 35 // Does strength reduction, constant folding, canonicalization, CFG simplification, DCE, and very 36 // simple CSE. This phase runs those optimizations to fixpoint. The goal of the phase is to 37 // dramatically reduce the complexity of the code. In the future, it's preferable to add optimizations 38 // to this phase rather than creating new optimizations because then the optimizations can participate 39 // in the fixpoint. However, because of the many interlocking optimizations, it can be difficult to 40 // add sophisticated optimizations to it. For that reason we have full CSE in a different phase, for 41 // example. 40 42 41 43 bool reduceStrength(Procedure&); -
trunk/Source/JavaScriptCore/b3/B3Validate.cpp
r195395 r195417 372 372 break; 373 373 } 374 375 VALIDATE(!(value->effects().writes && value->key()), ("At ", *value)); 374 376 } 375 377 } -
trunk/Source/WTF/ChangeLog
r195412 r195417 1 2016-01-21 Filip Pizlo <fpizlo@apple.com> 2 3 B3 should have load elimination 4 https://bugs.webkit.org/show_bug.cgi?id=153288 5 6 Reviewed by Geoffrey Garen. 7 8 I needed a way to track sets of ranges, where there is a high likelihood that all of the 9 ranges overlap. So I created RangeSet. It's a usually-sorted list of coalesced ranges. 10 Practically this means that right now, FTL B3 will end up with two kinds of range sets: a set 11 that just contains top and a set that contains nothing. In the future, most sets will either 12 be top of empty but some of them will contain a handful of other things. 13 14 * WTF.xcodeproj/project.pbxproj: 15 * wtf/CMakeLists.txt: 16 * wtf/MathExtras.h: 17 (WTF::leftShiftWithSaturation): 18 (WTF::nonEmptyRangesOverlap): 19 (WTF::rangesOverlap): 20 * wtf/RangeSet.h: Added. 21 (WTF::RangeSet::RangeSet): 22 (WTF::RangeSet::~RangeSet): 23 (WTF::RangeSet::add): 24 (WTF::RangeSet::contains): 25 (WTF::RangeSet::overlaps): 26 (WTF::RangeSet::clear): 27 (WTF::RangeSet::dump): 28 (WTF::RangeSet::dumpRaw): 29 (WTF::RangeSet::compact): 30 (WTF::RangeSet::overlapsNonEmpty): 31 (WTF::RangeSet::subsumesNonEmpty): 32 (WTF::RangeSet::findRange): 33 * wtf/StdLibExtras.h: 34 (WTF::binarySearchImpl): 35 (WTF::binarySearch): 36 (WTF::tryBinarySearch): 37 (WTF::approximateBinarySearch): 38 1 39 2016-01-19 Ada Chan <adachan@apple.com> 2 40 -
trunk/Source/WTF/WTF.xcodeproj/project.pbxproj
r195356 r195417 28 28 0F4570431BE5B58F0062A629 /* Dominators.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F4570421BE5B58F0062A629 /* Dominators.h */; }; 29 29 0F4570451BE834410062A629 /* BubbleSort.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F4570441BE834410062A629 /* BubbleSort.h */; }; 30 0F725CAC1C50461600AD943A /* RangeSet.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F725CAB1C50461600AD943A /* RangeSet.h */; }; 30 31 0F824A681B7443A0002E345D /* ParkingLot.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F824A641B7443A0002E345D /* ParkingLot.cpp */; }; 31 32 0F824A691B7443A0002E345D /* ParkingLot.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F824A651B7443A0002E345D /* ParkingLot.h */; }; … … 333 334 0F4570421BE5B58F0062A629 /* Dominators.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Dominators.h; sourceTree = "<group>"; }; 334 335 0F4570441BE834410062A629 /* BubbleSort.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BubbleSort.h; sourceTree = "<group>"; }; 336 0F725CAB1C50461600AD943A /* RangeSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RangeSet.h; sourceTree = "<group>"; }; 335 337 0F824A641B7443A0002E345D /* ParkingLot.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ParkingLot.cpp; sourceTree = "<group>"; }; 336 338 0F824A651B7443A0002E345D /* ParkingLot.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ParkingLot.h; sourceTree = "<group>"; }; … … 877 879 A8A472FC151A825B004123FF /* RandomNumber.h */, 878 880 A8A472FD151A825B004123FF /* RandomNumberSeed.h */, 881 0F725CAB1C50461600AD943A /* RangeSet.h */, 879 882 0F87105916643F190090B0AD /* RawPointer.h */, 880 883 A8A472FE151A825B004123FF /* RedBlackTree.h */, … … 1169 1172 0FD81AC5154FB22E00983E72 /* FastBitVector.h in Headers */, 1170 1173 A8A473C4151A825B004123FF /* FastMalloc.h in Headers */, 1174 0F725CAC1C50461600AD943A /* RangeSet.h in Headers */, 1171 1175 B38FD7BD168953E80065C969 /* FeatureDefines.h in Headers */, 1172 1176 0F9D3361165DBA73005AD387 /* FilePrintStream.h in Headers */, -
trunk/Source/WTF/wtf/CMakeLists.txt
r195304 r195417 78 78 RandomNumber.h 79 79 RandomNumberSeed.h 80 RangeSet.h 80 81 RawPointer.h 81 82 RedBlackTree.h -
trunk/Source/WTF/wtf/MathExtras.h
r195011 r195417 1 1 /* 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2013 Apple Inc. All rights reserved.2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2013, 2016 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 420 420 } 421 421 422 // Check if two ranges overlap assuming that neither range is empty. 423 template<typename T> 424 inline bool nonEmptyRangesOverlap(T leftMin, T leftMax, T rightMin, T rightMax) 425 { 426 ASSERT(leftMin < leftMax); 427 ASSERT(rightMin < rightMax); 428 429 if (leftMin <= rightMin && leftMax > rightMin) 430 return true; 431 if (rightMin <= leftMin && rightMax > leftMin) 432 return true; 433 return false; 434 } 435 422 436 // Pass ranges with the min being inclusive and the max being exclusive. For example, this should 423 437 // return false: … … 435 449 if (rightMin == rightMax) 436 450 return false; 437 438 if (leftMin <= rightMin && leftMax > rightMin) 439 return true; 440 if (rightMin <= leftMin && rightMax > leftMin) 441 return true; 442 return false; 451 452 return nonEmptyRangesOverlap(leftMin, leftMax, rightMin, rightMax); 443 453 } 444 454 -
trunk/Source/WTF/wtf/StdLibExtras.h
r194784 r195417 1 1 /* 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.2 * Copyright (C) 2008, 2016 Apple Inc. All Rights Reserved. 3 3 * Copyright (C) 2013 Patrick Gansterer <paroga@paroga.com> 4 4 * … … 213 213 } 214 214 215 if (mode == KeyMightNotBePresentInArray && !size)215 if (mode != KeyMustBePresentInArray && !size) 216 216 return 0; 217 217 … … 231 231 // If the element is not found, crash if asserts are enabled, and behave like approximateBinarySearch in release builds. 232 232 template<typename ArrayElementType, typename KeyType, typename ArrayType, typename ExtractKey> 233 inline ArrayElementType* binarySearch(ArrayType& array, size_t size, KeyType key, ExtractKeyextractKey = ExtractKey())233 inline ArrayElementType* binarySearch(ArrayType& array, size_t size, KeyType key, const ExtractKey& extractKey = ExtractKey()) 234 234 { 235 235 return binarySearchImpl<ArrayElementType, KeyType, ArrayType, ExtractKey, KeyMustBePresentInArray>(array, size, key, extractKey); … … 238 238 // Return zero if the element is not found. 239 239 template<typename ArrayElementType, typename KeyType, typename ArrayType, typename ExtractKey> 240 inline ArrayElementType* tryBinarySearch(ArrayType& array, size_t size, KeyType key, ExtractKeyextractKey = ExtractKey())240 inline ArrayElementType* tryBinarySearch(ArrayType& array, size_t size, KeyType key, const ExtractKey& extractKey = ExtractKey()) 241 241 { 242 242 return binarySearchImpl<ArrayElementType, KeyType, ArrayType, ExtractKey, KeyMightNotBePresentInArray>(array, size, key, extractKey); … … 245 245 // Return the element that is either to the left, or the right, of where the element would have been found. 246 246 template<typename ArrayElementType, typename KeyType, typename ArrayType, typename ExtractKey> 247 inline ArrayElementType* approximateBinarySearch(ArrayType& array, size_t size, KeyType key, ExtractKeyextractKey = ExtractKey())247 inline ArrayElementType* approximateBinarySearch(ArrayType& array, size_t size, KeyType key, const ExtractKey& extractKey = ExtractKey()) 248 248 { 249 249 return binarySearchImpl<ArrayElementType, KeyType, ArrayType, ExtractKey, ReturnAdjacentElementIfKeyIsNotPresent>(array, size, key, extractKey); … … 252 252 // Variants of the above that use const. 253 253 template<typename ArrayElementType, typename KeyType, typename ArrayType, typename ExtractKey> 254 inline ArrayElementType* binarySearch(const ArrayType& array, size_t size, KeyType key, ExtractKeyextractKey = ExtractKey())254 inline ArrayElementType* binarySearch(const ArrayType& array, size_t size, KeyType key, const ExtractKey& extractKey = ExtractKey()) 255 255 { 256 256 return binarySearchImpl<ArrayElementType, KeyType, ArrayType, ExtractKey, KeyMustBePresentInArray>(const_cast<ArrayType&>(array), size, key, extractKey); 257 257 } 258 258 template<typename ArrayElementType, typename KeyType, typename ArrayType, typename ExtractKey> 259 inline ArrayElementType* tryBinarySearch(const ArrayType& array, size_t size, KeyType key, ExtractKeyextractKey = ExtractKey())259 inline ArrayElementType* tryBinarySearch(const ArrayType& array, size_t size, KeyType key, const ExtractKey& extractKey = ExtractKey()) 260 260 { 261 261 return binarySearchImpl<ArrayElementType, KeyType, ArrayType, ExtractKey, KeyMightNotBePresentInArray>(const_cast<ArrayType&>(array), size, key, extractKey); 262 262 } 263 263 template<typename ArrayElementType, typename KeyType, typename ArrayType, typename ExtractKey> 264 inline ArrayElementType* approximateBinarySearch(const ArrayType& array, size_t size, KeyType key, ExtractKeyextractKey = ExtractKey())264 inline ArrayElementType* approximateBinarySearch(const ArrayType& array, size_t size, KeyType key, const ExtractKey& extractKey = ExtractKey()) 265 265 { 266 266 return binarySearchImpl<ArrayElementType, KeyType, ArrayType, ExtractKey, ReturnAdjacentElementIfKeyIsNotPresent>(const_cast<ArrayType&>(array), size, key, extractKey);
Note: See TracChangeset
for help on using the changeset viewer.