Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR improves performance of object iteration and indexing.
For example, calling
indexOf
on anArray<uint32_t>
object results in repeated calls to thedata()
method.Further, the C++ iterator implementation does the same.
A new speed test module has been added to evaulate performance. This uses some moderately large test objects and evaluates how long it takes to iterate through them using three methods:
for(unsigned i=0; i<array.count(); ++i)
loopfor(auto: array)
indexOf
methodArray has 1000 elements.
Vector has 367 elements, referencing 3208 bytes of string data.
Map<int, String> has 367 elements.
These are the results, in microseconds, on an esp8266:
Optimise iteration and
indexOf
operationThe regular
[]
operator andvalueAt
methods include range checks which are costly inside a loop.Adding
unsafe
methods skips these checks.Improve Vector search for char argument*
The
indexOf
method has been specialised forchar*
arguments so thatstrlen()
only needs to be called once. Previously it was called on every loop iteration.Provide base
==
operator which does binary comparisonThis allows easy searching by value (object content).
Rationalise string comparison methods
FlashStrings have three
equals
overloads forchar*
,String
andFlashString
arguments.We also require three
equalsignorecase
equivalents and appropriateoperator==
implementations.By adding an
ignoreCase
parameter to all threeequals
methods we can simplify code.Other improvements
printElement(Print, char)
specialization into source fileread
method out of header