FastLED 3.10.8
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 745 of file json.cpp.hpp.

745 {
746 auto arr = array_val->data.ptr<json_array>();
747 if (!arr) return array_val;
748
750
751 switch (type) {
752 case ALL_UINT8: {
753 fl::vector<u8> vec;
754 vec.reserve(arr->size());
755 for (const auto& elem : *arr) {
756 auto val = elem->as_int();
757 if (val) vec.push_back(static_cast<u8>(*val));
758 }
760 }
761
762 case ALL_INT16: {
763 fl::vector<i16> vec;
764 vec.reserve(arr->size());
765 for (const auto& elem : *arr) {
766 auto val = elem->as_int();
767 if (val) vec.push_back(static_cast<i16>(*val));
768 }
770 }
771
772 case ALL_FLOATS: {
773 fl::vector<float> vec;
774 vec.reserve(arr->size());
775 for (const auto& elem : *arr) {
776 if (elem->is_float()) {
777 auto val = elem->as_float();
778 if (val) vec.push_back(*val);
779 } else if (elem->is_int()) {
780 auto val = elem->as_int();
781 if (val) {
782 // Route i64 -> float via i32 to avoid the direct cast
783 // pulling libgcc-nofp's `_floatdisf.o` (~5 KB of soft-FP
784 // double cascade) on no-FPU targets. ALL_FLOATS
785 // classification only fires when every int is within
786 // +/-2^24 anyway (classify_array line 717), so the int32
787 // narrowing is lossless. See FastLED #3076.
788 vec.push_back(static_cast<float>(static_cast<fl::i32>(*val)));
789 }
790 }
791 }
793 }
794
795 default:
796 return array_val; // Keep as generic array
797 }
798}
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
constexpr remove_reference< T >::type && move(T &&t) FL_NO_EXCEPT
Definition move.h:30
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:672
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::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: