@@ -5,16 +5,19 @@ class ArrayIterationUnroller::InternalPerform final
55 InternalPerform (ArrayIterationUnroller& o) :
66 owner (o)
77 {
8- jumpTable[0 ] = &InternalPerform::singles;
9- jumpTable[1 ] = &InternalPerform::pairs;
10- jumpTable[2 ] = &InternalPerform::triples;
11- jumpTable[3 ] = &InternalPerform::quads;
12- jumpTable[4 ] = &InternalPerform::quints;
13- jumpTable[5 ] = &InternalPerform::sexts;
14- jumpTable[6 ] = &InternalPerform::septs;
15- jumpTable[7 ] = &InternalPerform::octs;
16- jumpTable[8 ] = &InternalPerform::nonuples;
17- jumpTable[9 ] = &InternalPerform::decas;
8+ jumpTable =
9+ {
10+ std::bind (&InternalPerform::singles, this , std::placeholders::_1),
11+ std::bind (&InternalPerform::pairs, this , std::placeholders::_1),
12+ std::bind (&InternalPerform::triples, this , std::placeholders::_1),
13+ std::bind (&InternalPerform::quads, this , std::placeholders::_1),
14+ std::bind (&InternalPerform::quints, this , std::placeholders::_1),
15+ std::bind (&InternalPerform::sexts, this , std::placeholders::_1),
16+ std::bind (&InternalPerform::septs, this , std::placeholders::_1),
17+ std::bind (&InternalPerform::octs, this , std::placeholders::_1),
18+ std::bind (&InternalPerform::nonuples, this , std::placeholders::_1),
19+ std::bind (&InternalPerform::decas, this , std::placeholders::_1)
20+ };
1821 }
1922
2023 // ==============================================================================
@@ -94,21 +97,17 @@ class ArrayIterationUnroller::InternalPerform final
9497 }
9598
9699 // ==============================================================================
97- /* * This will iterate through the array with a jump table */
98- void runBranched (int index, int offset)
99- {
100- (this ->*jumpTable[index]) (offset);
101- }
100+ /* * Typedef for creating a member-function-pointer array. */
101+ using MethodPointer = std::function<void (int )>;
102102
103- // ==============================================================================
104103 /* * This will perform an iteration with the specified increment.
105104
106105 Be sure to specify the correct method to the increment!
107106
108107 @param[out] remainder The remainder of elements that need to be iterated through.
109108 @param increment The amount of items to process and therefore to increment by.
110109 */
111- template <void (InternalPerform::* unrollMethod) ( int index) >
110+ template <auto unrollMethod>
112111 void callMethodWithIncrement (int & remainder, int increment)
113112 {
114113 // Find out how many blocks of "increment" elements we can iterate through:
@@ -124,12 +123,7 @@ class ArrayIterationUnroller::InternalPerform final
124123private:
125124 // ==============================================================================
126125 ArrayIterationUnroller& owner;
127-
128- // ==============================================================================
129- /* * Typedef for creating a member-function-pointer array. */
130- typedef void (InternalPerform::*MethodPointer) (int );
131-
132- MethodPointer jumpTable[10 ]; // NB: Do NOT make this static - this will not work in a multi-threaded environment!
126+ std::array<MethodPointer, 10 > jumpTable;
133127
134128 // ==============================================================================
135129 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (InternalPerform)
@@ -142,10 +136,6 @@ ArrayIterationUnroller::ArrayIterationUnroller (int arraySize) :
142136 jassert (sizeOfArray >= 0 );
143137}
144138
145- ArrayIterationUnroller::~ArrayIterationUnroller ()
146- {
147- }
148-
149139// ==============================================================================
150140void ArrayIterationUnroller::resize (int newSize)
151141{
@@ -179,18 +169,19 @@ void ArrayIterationUnroller::run()
179169
180170 auto remainder = sizeOfArray;
181171
182- #if SQUAREPINE_ARRAY_ITERATION_UNROLLER_CHECK_BIG_NUMS
183172 while (remainder >= 100 )
184173 perf.callMethodWithIncrement <&InternalPerform::hundred> (remainder, 100 );
185- #endif
186174
187175 while (remainder >= 20 )
188176 perf.callMethodWithIncrement <&InternalPerform::twenty> (remainder, 20 );
189177
190- if (remainder >= 10 )
178+ while (remainder >= 10 )
191179 perf.callMethodWithIncrement <&InternalPerform::decas> (remainder, 10 );
192180
193- if (remainder > 0 )
194- perf.runBranched (remainder - 1 , sizeOfArray - remainder);
181+ while (remainder >= 2 )
182+ perf.callMethodWithIncrement <&InternalPerform::pairs> (remainder, 2 );
183+
184+ while (remainder > 0 )
185+ perf.callMethodWithIncrement <&InternalPerform::singles> (remainder, 1 );
195186 #endif
196187}
0 commit comments