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` |
| 15 | * `absl::make_unique` and `absl::WrapUnique` |
| 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 |
| 25 | `absl/algorithm/container.h` |
Danil Chapovalov | 47cf5ea | 2019-02-19 19:20:16 | [diff] [blame] | 26 | * The macros in `absl/base/attributes.h` and `absl/base/config.h` |
Karl Wiberg | c3af97d | 2018-08-27 02:26:18 | [diff] [blame] | 27 | |
| 28 | ## **Disallowed** |
| 29 | |
| 30 | ### `absl::Mutex` |
| 31 | |
| 32 | *Use `rtc::CriticalSection` instead.* |
| 33 | |
| 34 | Chromium has a ban on new static initializers, and `absl::Mutex` uses |
| 35 | one. To make `absl::Mutex` available, we would need to nicely ask the |
| 36 | Abseil team to remove that initializer (like they already did for a |
| 37 | spinlock initializer). Additionally, `absl::Mutex` handles time in a |
| 38 | way that may not be compaible with the rest of WebRTC. |
| 39 | |
| 40 | ### `absl::Span` |
| 41 | |
| 42 | *Use `rtc::ArrayView` instead.* |
| 43 | |
| 44 | `absl::Span` differs from `rtc::ArrayView` on several points, and both |
| 45 | of them differ from the `std::span` that was voted into |
| 46 | C++20—and `std::span` is likely to undergo further changes |
| 47 | before C++20 is finalized. We should just keep using `rtc::ArrayView` |
| 48 | and avoid `absl::Span` until C++20 is finalized and the Abseil team |
| 49 | has decided if they will change `absl::Span` to match. |
| 50 | [Bug](https://bugs.webrtc.org/9214). |
| 51 | |
Karl Wiberg | bd0deca | 2019-02-26 00:42:26 | [diff] [blame] | 52 | ### `absl::StrCat`, `absl::StrAppend`, `absl::StrJoin`, `absl::StrSplit` |
Karl Wiberg | c3af97d | 2018-08-27 02:26:18 | [diff] [blame] | 53 | |
Karl Wiberg | bd0deca | 2019-02-26 00:42:26 | [diff] [blame] | 54 | *Use `rtc::SimpleStringBuilder` to build strings.* |
Karl Wiberg | c3af97d | 2018-08-27 02:26:18 | [diff] [blame] | 55 | |
| 56 | These are optimized for speed, not binary size. Even `StrCat` calls |
| 57 | with a modest number of arguments can easily add several hundred bytes |
| 58 | to the binary. |