Karl Wiberg | c3af97d | 2018-08-27 02:26:18 | [diff] [blame] | 1 | # Using Abseil in WebRTC |
| 2 | |
| 3 | You may use a subset of the utilities provided by the [Abseil][abseil] |
| 4 | library when writing WebRTC C++ code. Below, we list the explicitly |
| 5 | *allowed* and the explicitly *disallowed* subsets of Abseil; if you |
| 6 | find yourself in need of something that isn’t in either subset, |
| 7 | please add it to the *allowed* subset in this doc in the same CL that |
| 8 | adds the first use. |
| 9 | |
| 10 | [abseil]: https://abseil.io/about/ |
| 11 | |
| 12 | ## **Allowed** |
| 13 | |
| 14 | * `absl::InlinedVector` |
Mirko Bonadei | c128df1 | 2019-09-18 05:59:07 | [diff] [blame] | 15 | * `absl::WrapUnique` |
Karl Wiberg | c3af97d | 2018-08-27 02:26:18 | [diff] [blame] | 16 | * `absl::optional` and related stuff from `absl/types/optional.h`. |
| 17 | * `absl::string_view` |
Steve Anton | 1c9c9fc | 2019-02-14 23:13:09 | [diff] [blame] | 18 | * The functions in `absl/strings/ascii.h`, `absl/strings/match.h`, |
| 19 | and `absl/strings/str_replace.h`. |
Jiawei Ou | a6e034a | 2018-11-25 04:59:41 | [diff] [blame] | 20 | * `absl::is_trivially_copy_constructible`, |
| 21 | `absl::is_trivially_copy_assignable`, and |
| 22 | `absl::is_trivially_destructible` from `absl/meta/type_traits.h`. |
Karl Wiberg | c3af97d | 2018-08-27 02:26:18 | [diff] [blame] | 23 | * `absl::variant` and related stuff from `absl/types/variant.h`. |
Steve Anton | e76ca61 | 2019-01-25 20:49:14 | [diff] [blame] | 24 | * The functions in `absl/algorithm/algorithm.h` and |
Elad Alon | e86af2c | 2019-06-03 12:37:50 | [diff] [blame] | 25 | `absl/algorithm/container.h`. |
| 26 | * The macros in `absl/base/attributes.h`, `absl/base/config.h` and |
| 27 | `absl/base/macros.h`. |
Karl Wiberg | c3af97d | 2018-08-27 02:26:18 | [diff] [blame] | 28 | |
| 29 | ## **Disallowed** |
| 30 | |
Mirko Bonadei | c128df1 | 2019-09-18 05:59:07 | [diff] [blame] | 31 | ### `absl::make_unique` |
| 32 | |
| 33 | *Use `std::make_unique` instead.* |
| 34 | |
Karl Wiberg | c3af97d | 2018-08-27 02:26:18 | [diff] [blame] | 35 | ### `absl::Mutex` |
| 36 | |
| 37 | *Use `rtc::CriticalSection` instead.* |
| 38 | |
| 39 | Chromium has a ban on new static initializers, and `absl::Mutex` uses |
| 40 | one. To make `absl::Mutex` available, we would need to nicely ask the |
| 41 | Abseil team to remove that initializer (like they already did for a |
| 42 | spinlock initializer). Additionally, `absl::Mutex` handles time in a |
Rasmus Brandt | 7ab41e5 | 2019-12-18 09:01:54 | [diff] [blame] | 43 | way that may not be compatible with the rest of WebRTC. |
Karl Wiberg | c3af97d | 2018-08-27 02:26:18 | [diff] [blame] | 44 | |
| 45 | ### `absl::Span` |
| 46 | |
| 47 | *Use `rtc::ArrayView` instead.* |
| 48 | |
| 49 | `absl::Span` differs from `rtc::ArrayView` on several points, and both |
| 50 | of them differ from the `std::span` that was voted into |
| 51 | C++20—and `std::span` is likely to undergo further changes |
| 52 | before C++20 is finalized. We should just keep using `rtc::ArrayView` |
| 53 | and avoid `absl::Span` until C++20 is finalized and the Abseil team |
| 54 | has decided if they will change `absl::Span` to match. |
| 55 | [Bug](https://bugs.webrtc.org/9214). |
| 56 | |
Karl Wiberg | bd0deca | 2019-02-26 00:42:26 | [diff] [blame] | 57 | ### `absl::StrCat`, `absl::StrAppend`, `absl::StrJoin`, `absl::StrSplit` |
Karl Wiberg | c3af97d | 2018-08-27 02:26:18 | [diff] [blame] | 58 | |
Karl Wiberg | bd0deca | 2019-02-26 00:42:26 | [diff] [blame] | 59 | *Use `rtc::SimpleStringBuilder` to build strings.* |
Karl Wiberg | c3af97d | 2018-08-27 02:26:18 | [diff] [blame] | 60 | |
| 61 | These are optimized for speed, not binary size. Even `StrCat` calls |
| 62 | with a modest number of arguments can easily add several hundred bytes |
| 63 | to the binary. |