Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup #209

Open
wants to merge 58 commits into
base: main
Choose a base branch
from
Open

Cleanup #209

wants to merge 58 commits into from

Conversation

ol-imorozko
Copy link
Collaborator

No description provided.

@ol-imorozko ol-imorozko changed the title Cleanup: remove inline keyword from functions defined within a class definition and apply clang-format Cleanup Sep 25, 2024
@ol-imorozko ol-imorozko changed the title Cleanup WIP: Cleanup Sep 26, 2024
@ol-imorozko ol-imorozko force-pushed the cleanup branch 12 times, most recently from 9e8eb02 to f1adb36 Compare October 1, 2024 11:20
@ol-imorozko ol-imorozko changed the title WIP: Cleanup Cleanup Oct 1, 2024
@ol-imorozko ol-imorozko force-pushed the cleanup branch 4 times, most recently from 6c9f2be to 284e4fe Compare October 2, 2024 11:14
This is completly redundant:
[class.mfct]: "A member function may be defined (9.5) in its class
definition, in which case it is an inline (9.2.7) member
function if it is attached to the global module"

Moreover, the inline keyword has nothing to do with inlining.
It's about whether multiple identical definitions of the
function are permitted in different translation units
- Replace C-style casts with const_cast
- Switch to std::string for safer argument handling
- Eliminate redundant C-style casting to char*
- Use range-based loops
- use std:: namespace with signal/strcmp
- Use `aligned_storage` with `std::array` instead of C-style array.

- Due to that, remove now unnecessary `sizeof(T)` multiplication in `std::copy`.

- Use `std::launder` to ensure compliance with [basic.life]/8 rule,
  Basically, [basic.life]/8 tells us that, if you allocate a new object in the
  storage of the old one, you cannot access the new object through pointers to
  the old. launder allows us to side-step that.

- Refactor `push_back` to use make it accept both lvalues and rvalues.

- Modify `PushBackUnsafe` to accept both lvalues and rvalues.

- Squash `PerElementCopy`, `PerElementMove`, and `TrivialCopy` into a single
  `PerElementTransfer`, using `PushBackUnsafe` or `std::copy` based on `T` type traits.

- Replace `#define`-based exception handling with a template boolean parameter

- Add missing destructor to ensure proper cleanup.

- Avoid assignment operator usage in constructors to prevent default object creation.

- Add missing `clear` in move assignment operator.

- Remove redundant `return` and `abort` statements after `HandleOutOfRange`.

- Add missing `noexcept` specifier to move operations.
Args is a common name for variadic templates, plus it adds consistency
since other places in the code uses Args
- is_optional_v for std::optional detection.
- is_variant_v for std::variant detection.
- is_container_v for general container detection.
- is_vector_v for std::vector detection.
- is_set_v for std::set detection.
- Replace `arg_T` with `T`. More consistency this way.

- Replace a lot of to_string functions with just one that
  uses if constexpr to determine a correct action on compile-time

- Mark functions as `inline` to avoid violating ODR since
  they are defined in the header and not static

- Avoid unnecessary copies of the `config_t` structure by
  passing it as a `const` reference.

- std::ostringstream for container concatenation,
  simplifying `std::vector` and `std::set` implementations.

- Replace `if-else` blocks with ternary operators for more
  concise return statements.

- Add an ability to provide std::string_view
Otherwise we will be unable to use table_t which uses to_string function
from converter.h since the default_value_t is not constructible with
std::string.
Add functions zip_apply that applies function and zip_apply_collect
that applies function and stores results in std::array.

zip_apply_collect is actully unused now, but I've added it just in case
- Replace #define with constexpr for YANET_TSC_BINS_N and YANET_TSC_BINS_SHIFT constants.
- Use C++ standard alignas instead of __attribute__((aligned)).
- Introduce CountersArray alias for std::array<uint16_t, YANET_TSC_BINS_N> to avoid C-style arrays.
- Use std::clamp instead of std::min and std::max for clarity.
- Replace deprecated std::is_pod with std::is_trivially_copyable and std::is_standard_layout
This will help reduce boilerplate code later by utilizing fold expressions
Enables insertion of values from containers
- Mark functions as `inline` instead of `static` where appropriate.
- Replace `printf` with `std::ostream` for safer and more idiomatic C++ code.
- Use structured bindings to improve readability, replacing `std::get` usage.
- Add a template function `lpmLookupAddress` to eliminate duplicated code between IPv4 and IPv6 lookups.
- Use `auto&` instead of `auto` to prevent unnecessary copies of request objects.
- Utilize `SharedMemory` class for managing shared memory instead of raw `shmget` and `shmat`.
- Remove the use of `protected` since no inheritance is required; switch to `private`.
- Remove unnecessary forward declaration of `overflow_store`.
- Replace C-style arrays with `std::array`.
- Use `utils::zip_apply` to reduce boilerplate code and improve maintainability.
This is a common utility function, so it has been relocated to utils.h.
This is a common utility, and it was previously duplicated in three places.

Also changed the input parameter from const char* to std::string_view
ans use std::string_view::find for faster string splitting.
table_t is bland and not so informative. The purpose of this class
is to print it's content, so rename it to TablePrinter
- Add perfect forwarding of arguments in insert_row
- Introduce insert_row overloads for ranges and pairs
- Renamed insert to insert_row for clarity
- Added an insert_row method to directly handle tuples,
  avoiding unnecessary casting from tuples to vectors.

- Simplified common code patterns such as:
  ```cpp
  TablePrinter table;
  table.insert("id", "name");
  for (const auto& [id, name] : response) {
      table.insert(id, name);
  }
  table.print();
  ```
  by replacing them with a single helper function.

- Rename private fields and public methos according to google codingstyle
- Simplify print* methods by utilizing unordered_map for indices
Otherwise the following refactoring of call method will fail
- Use a single template for both std::optional and non-optional types.
- Replace std::stoull with std::from_chars or std::istringstream based
  on GCC version. We should support GCC 7.5, but unfortunately it
  supports not full set of C++17 features. #include <charconv> is unsupported
- Replaced recursive template functions with a single function utilizing
  std::index_sequence and fold expressions to iterate over tuple elements.
- Add support for floating-point arguments
- Remove casting of call argument to a function pointer. Now it can
  accept any callable which is more efficient and extensive
- Rename it to Call (google codestyle)
Lack of unittests for yanet-cli is bad.
Started with unittests for Call helper function
This is a function defined in a header hence it should be inline
Replaced repetitive pop/push method implementations with a SERIALIZABLE macro
that defines as_tuple method to get fields of a structure as a tuple.
This reduces boilerplate code and improves readability.
It's a trivially copyable type, it will get serialized via default
means implemented in stream.h
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant