mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 18:18:18 +00:00
7348bf4d56
5246: Use std::vector instead of sorted_array, remove base/tl/sorted_array.h r=def- a=heinrich5991 This replaces all usages of `sorted_array` with `std::vector`. This requires the following general changes: - `add_unsorted` is replaced with `push_back`. - `add` is replaced with `push_back` and subsequent `sort` or `stable_sort` must be ensured. - In some cases, immediately sorting the entire list after adding an item was unavoidable. Previously items were added at the correct position, which was O(N) because all items after the inserted one had to be moved in any case. - `sort_range` is replaced with `sort` or `stable_sort`. - `size` returns a `size_t` instead of `int`, so to fix sign comparison warnings, casts are added where necessary or types of loop variables are changed to `size_t` where possible. For-each loops are also used where possible / where required by clang-tidy. - `find_binary` is replaced with `std::equal_range`. This can only find items of the same type, so some wrappers, that only have the relevant fields set, need to be created for searching. In terms of behavior, this should not change anything, except maybe `CLocalizationDatabase` for the better. As far as I understand it, at lot of the code there was not doing anything. It assumes that binary search can return a range of multiple entries, but the equality/comparison function is based on hash and context hash. This means that any item in this range will match the given hash and context hash already, so all of the following checks are redundant. I changed this to first do a lookup with the hash and context hash and if that fails do another lookup with the default context hash. I have also already replaced `base/tl/array.h` with `std::vector`, removing all of `base/tl` except `threading.h`. I'll make a separate PR later because this caused a lot more changes especially in the editor that I first want to test and review myself. Naming of `array`/`sorted_array`/`std::vector` variables was rather inconsistent (sometimes prefix `a` or `l` is used), so ~~I chose to not use any prefix for all new `std::vector`s~~ heinrich5991 left them as-is. ## Checklist - [X] Tested the change ingame - [ ] Provided screenshots if it is a visual change - [ ] Tested in combination with possibly related configuration options - [ ] Written a unit test if it works standalone, system.c especially - [ ] Considered possible null pointers and out of bounds array indexing - [ ] Changed no physics that affect existing maps - [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional) Co-authored-by: Robert Müller <robytemueller@gmail.com> |
||
---|---|---|
.. | ||
tl | ||
unicode | ||
color.h | ||
detect.h | ||
dynamic.h | ||
hash.cpp | ||
hash.h | ||
hash_bundled.cpp | ||
hash_ctxt.h | ||
hash_libtomcrypt.cpp | ||
hash_openssl.cpp | ||
log.cpp | ||
log.h | ||
logger.h | ||
math.h | ||
system.cpp | ||
system.h | ||
vmath.h |