FastLED 3.10.10
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 807 of file json.cpp.hpp.

807 {
808 auto arr = array_val->data.ptr<json_array>();
809 if (!arr) return array_val;
810
812
813 switch (type) {
814 case ALL_UINT8: {
815 fl::vector<u8> vec;
816 vec.reserve(arr->size());
817 for (const auto& elem : *arr) {
818 auto val = elem->as_int();
819 if (val) vec.push_back(static_cast<u8>(*val));
820 }
822 }
823
824 case ALL_INT16: {
825 fl::vector<i16> vec;
826 vec.reserve(arr->size());
827 for (const auto& elem : *arr) {
828 auto val = elem->as_int();
829 if (val) vec.push_back(static_cast<i16>(*val));
830 }
832 }
833
834 case ALL_FLOATS: {
835 fl::vector<float> vec;
836 vec.reserve(arr->size());
837 for (const auto& elem : *arr) {
838 if (elem->is_float()) {
839 auto val = elem->as_float();
840 if (val) vec.push_back(*val);
841 } else if (elem->is_int()) {
842 auto val = elem->as_int();
843 if (val) {
844 // Route i64 -> float via i32 to avoid the direct cast
845 // pulling libgcc-nofp's `_floatdisf.o` (~5 KB of soft-FP
846 // double cascade) on no-FPU targets. ALL_FLOATS
847 // classification only fires when every int is within
848 // +/-2^24 anyway (classify_array line 717), so the int32
849 // narrowing is lossless. See FastLED #3076.
850 vec.push_back(static_cast<float>(static_cast<fl::i32>(*val)));
851 }
852 }
853 }
855 }
856
857 default:
858 return array_val; // Keep as generic array
859 }
860}
void reserve(fl::size n) FL_NO_EXCEPT
Definition vector.h:591
void push_back(const T &value) FL_NO_EXCEPT
Definition vector.h:624
shared_ptr< T > make_shared(Args &&... args) FL_NO_EXCEPT
Definition shared_ptr.h:423
ArrayType classify_array(const json_array &arr) FL_NO_EXCEPT
Definition json.cpp.hpp:729
constexpr remove_reference< T >::type && move(T &&t) FL_NO_EXCEPT
Definition s16x16x4.h:30
unsigned char u8
Definition stdint.h:132
fl::vector< fl::shared_ptr< json_value > > json_array
Definition types.h:54

References ALL_FLOATS, ALL_INT16, ALL_UINT8, classify_array(), fl::FL_NO_EXCEPT, fl::adl_barrier::make_shared(), fl::fl::adl_barrier::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: