Commit graph

7 commits

Author SHA1 Message Date
Lenny Maiorani 178190ab52 MACAddress: Use all_of to implement is_zero
Problem:
- `is_zero()` is implemented by checking each value in the array by
  hand. This is error-prone and less expressive than using an
  algorithm.

Solution:
- Implement `is_zero()` in terms of `all_of`.
2020-11-21 19:25:14 +01:00
Lenny Maiorani bdf3baa8ac MACAddress: AK::Array as member variable instead of C-array
Problem:
- C-style arrays do not automatically provide bounds checking and are
  less type safe overall.
- `__builtin_memcmp` is not a constant expression in the current gcc.

Solution:
- Change private m_data to be AK::Array.
- Eliminate constructor from C-style array.
- Change users of the C-style array constructor to use the default
  constructor.
- Change `operator==()` to be a hand-written comparison loop and let
  the optimizer figure out to use `memcmp`.
2020-11-20 21:18:14 +01:00
Lenny Maiorani 964d2e0dd0 MACAddress: constexpr support
Problem:
- `MACAddress` class is not usable in a compile-time context.
- `__builtin_memcpy` is not constexpr in gcc.

Solution:
- Decorate functions with `constexpr` keyword.
- Use default constructors and destructors.
- Change `__builtin_memcpy` to a hand-written `for` loop and let the
  compiler's optimizer take care of it.
- Add tests to ensure compile-time capabilities.
2020-11-19 14:03:47 +01:00
Lenny Maiorani fd97f23cef MACAddress: Unit testing for basic functionality
Problem:
- There are no unit tests for `MACAddress` class. This makes it
  difficult to refactor and ensure the same behavior.
- `m_data` private member variable is uninitialized leading to undefined
  behavior of `is_zero()`.

Solution:
- Add unit tests to cover basic functionality.
- Initialize `m_data`.
2020-11-17 09:47:50 +01:00
asynts 1d96d5eea4 AK: Use new format functions. 2020-10-08 09:59:55 +02:00
Ben Wiederhake 8940bc3503 Meta+AK: Make clang-format-10 clean 2020-09-25 21:18:17 +02:00
AnotherTest 7d0bf9b5a9 Kernel+AK: Separate out MACAddress and move it into AK 2020-04-05 09:50:48 +02:00
Renamed from Kernel/Net/MACAddress.h (Browse further)