llvm-project
e92c19ab - [libc] Add cpp::swap and cpp::clamp utilities (#221236)

Commit
73 days ago
[libc] Add cpp::swap and cpp::clamp utilities (#221236) Added cpp::swap to src/__support/CPP/utility/swap.h with move semantics and array support, and cpp::clamp to src/__support/CPP/algorithm.h with comparator support. Included unit tests in swap_test.cpp and algorithm_test.cpp. Adopted the new utilities in initial callsites: * stdlib: Used cpp::swap in qsort_data.h * wctype: Used cpp::swap in perfect_hash_map.h * math: Used cpp::clamp in powf.h * scanf_core: Used cpp::min and cpp::max in parser.h Also fixed sign extension when parsing scanset specifiers in parser.h: signed characters greater than or equal to 128 produced negative values, inverting comparisons and causing out-of-bounds writes in the bitset. Scanset characters are now cast through uint8_t, and non-ASCII tests were added to parser_test.cpp. Assisted-by: Automated tooling, human reviewed.
Author
Parents
Loading