common: Improve printBuffer() & added unit tests
This patchset is improved version of the existing code for several
reasons:
1.The code is more concise and easier to read. It uses modern C++
features such as `std::ranges::for_each` and `std::format`, which
express the intent of the code more clearly compared to the nested
if-else statements and manual formatting.
2.The code now has fewer lines of code and avoids the need for creating
and managing an `std::ostringstream` object manually, which simplifies
the function and reduces the risk of errors.
3.This patch uses type-safe range-based for loop and `uint8_t` type
directly, whereas the existing code uses `int` for iterating over the
buffer elements, which may lead to unintentional type conversions or
loss of precision.
4.While the performance impact may not be significant for this patch,
using `std::ranges::for_each` with lambdas might allow for more
optimization opportunities by the compiler compared to the traditional
loop used in existing code.
Overall, this patchset leverages modern C++ features to achieve the same
functionality in a more concise, readable, and type-safe manner, making
it preferable.
Change-Id: I7be547ade053638cb4ca459ee795195f6f0883bf
Signed-off-by:
Manojkiran Eda <manojkiran.eda@gmail.com>
Loading
Please register or sign in to comment