FastLED 3.10.9
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 802 of file json.cpp.hpp.

802 {
803 auto arr = array_val->data.ptr<json_array>();
804 if (!arr) return array_val;
805
807
808 switch (type) {
809 case ALL_UINT8: {
810 fl::vector<u8> vec;
811 vec.reserve(arr->size());
812 for (const auto& elem : *arr) {
813 auto val = elem->as_int();
814 if (val) vec.push_back(static_cast<u8>(*val));
815 }
817 }
818
819 case ALL_INT16: {
820 fl::vector<i16> vec;
821 vec.reserve(arr->size());
822 for (const auto& elem : *arr) {
823 auto val = elem->as_int();
824 if (val) vec.push_back(static_cast<i16>(*val));
825 }
827 }
828
829 case ALL_FLOATS: {
830 fl::vector<float> vec;
831 vec.reserve(arr->size());
832 for (const auto& elem : *arr) {
833 if (elem->is_float()) {
834 auto val = elem->as_float();
835 if (val) vec.push_back(*val);
836 } else if (elem->is_int()) {
837 auto val = elem->as_int();
838 if (val) {
839 // Route i64 -> float via i32 to avoid the direct cast
840 // pulling libgcc-nofp's `_floatdisf.o` (~5 KB of soft-FP
841 // double cascade) on no-FPU targets. ALL_FLOATS
842 // classification only fires when every int is within
843 // +/-2^24 anyway (classify_array line 717), so the int32
844 // narrowing is lossless. See FastLED #3076.
845 vec.push_back(static_cast<float>(static_cast<fl::i32>(*val)));
846 }
847 }
848 }
850 }
851
852 default:
853 return array_val; // Keep as generic array
854 }
855}
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:131
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: