ddnet/src/base
bors[bot] 7348bf4d56
Merge #5246
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>
2022-05-27 08:51:55 +00:00
..
tl Remove base/tl/sorted_array.h 2022-05-27 00:03:13 +02:00
unicode Changed file names to match classic source.c include header.h 2022-05-07 00:54:29 +02:00
color.h Fixed some useless double promotion 2022-03-23 18:22:08 +01:00
detect.h Emscripten support 2022-03-25 12:42:18 +01:00
dynamic.h Run clang-format 2020-09-26 21:50:15 +02:00
hash.cpp Added external linkage instead of static const 2022-04-03 01:12:27 +02:00
hash.h Added external linkage instead of static const 2022-04-03 01:12:27 +02:00
hash_bundled.cpp Use cpp 2021-06-24 17:19:17 +02:00
hash_ctxt.h uint64 -> uint64_t, int64 -> int64_t 2021-06-24 17:19:17 +02:00
hash_libtomcrypt.cpp Add modernize-deprecated-headers 2022-02-15 00:22:52 +01:00
hash_openssl.cpp Use cpp 2021-06-24 17:19:17 +02:00
log.cpp Don't enable colors when stdout is redirected to a file (fixes #5233) 2022-05-26 12:32:24 +02:00
log.h Add logging macros log_{error,warn,info,debug,trace} 2022-04-29 15:32:42 +02:00
logger.h Unify logging infrastructure between IConsole and dbg_msg 2022-04-29 15:21:26 +02:00
math.h Use std::gcd 2022-04-28 17:01:53 +02:00
system.cpp Switch to nanoseconds 2022-05-18 18:05:41 +02:00
system.h Switch to nanoseconds 2022-05-18 18:05:41 +02:00
vmath.h asan+ubsan clean 2022-05-26 01:22:14 +02:00