FastLED 3.9.15
Loading...
Searching...
No Matches

◆ optimize_array()

fl::shared_ptr< json_value > fl::anonymous_namespace{json.cpp.hpp}::optimize_array ( fl::shared_ptr< json_value > array_val)

Definition at line 733 of file json.cpp.hpp.

733 {
734 auto arr = array_val->data.ptr<json_array>();
735 if (!arr) return array_val;
736
738
739 switch (type) {
740 case ALL_UINT8: {
741 fl::vector<u8> vec;
742 vec.reserve(arr->size());
743 for (const auto& elem : *arr) {
744 auto val = elem->as_int();
745 if (val) vec.push_back(static_cast<u8>(*val));
746 }
748 }
749
750 case ALL_INT16: {
751 fl::vector<i16> vec;
752 vec.reserve(arr->size());
753 for (const auto& elem : *arr) {
754 auto val = elem->as_int();
755 if (val) vec.push_back(static_cast<i16>(*val));
756 }
758 }
759
760 case ALL_FLOATS: {
761 fl::vector<float> vec;
762 vec.reserve(arr->size());
763 for (const auto& elem : *arr) {
764 if (elem->is_float()) {
765 auto val = elem->as_float();
766 if (val) vec.push_back(*val);
767 } else if (elem->is_int()) {
768 auto val = elem->as_int();
769 if (val) {
770 // Route i64 -> float via i32 to avoid the direct cast
771 // pulling libgcc-nofp's `_floatdisf.o` (~5 KB of soft-FP
772 // double cascade) on no-FPU targets. ALL_FLOATS
773 // classification only fires when every int is within
774 // +/-2^24 anyway (classify_array line 717), so the int32
775 // narrowing is lossless. See FastLED #3076.
776 vec.push_back(static_cast<float>(static_cast<fl::i32>(*val)));
777 }
778 }
779 }
781 }
782
783 default:
784 return array_val; // Keep as generic array
785 }
786}
void reserve(fl::size n) FL_NOEXCEPT
Definition vector.h:591
void push_back(const T &value) FL_NOEXCEPT
Definition vector.h:624
ArrayType classify_array(const json_array &arr)
Definition json.cpp.hpp:660
constexpr remove_reference< T >::type && move(T &&t) FL_NOEXCEPT
Definition s16x16x4.h:28
unsigned char u8
Definition stdint.h:131
shared_ptr< T > make_shared(Args &&... args) FL_NOEXCEPT
Definition shared_ptr.h:414
fl::vector< fl::shared_ptr< json_value > > json_array
Definition types.h:33

References ALL_FLOATS, ALL_INT16, ALL_UINT8, classify_array(), fl::make_shared(), fl::fl::move(), optimize_array(), fl::vector< T >::push_back(), and fl::vector< T >::reserve().

Referenced by fl::anonymous_namespace{json.cpp.hpp}::JsonBuilder::on_token(), and optimize_array().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: