Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use get_or_insert_with in common_cache()
There was a question whether this is equally performant. There are multiple good reasons why it should be: 1. `get_or_insert_with` is marked `#[inline]` 2. Any good optimizer will inline a function that is used exactly once 3. 1 and 2 conclude that the closure will get inlined 4. Computing self.tx can then be moved to the only branch where it is required. 5. Even if get_or_insert_with didn't get optimized, which is extremely unlikely, the `tx` field is at the beginning of the struct and it probably has pointer alignment (`Deref` suggests it's a pointer). Alignment larger than pointer is not used, so we can expect the fields to be ordered as-defined. (This is not guaranteed by Rust but there's not good reason to change the order in this case.) We can assume that offset to tx is zero in most cases which means no computation is actually needed so the expression before closure is no-op short of passing it into the closure as an argument. At the time of writing `#[inline]` can be seen at https://doc.rust-lang.org/src/core/option.rs.html#933
- Loading branch information