You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The particular case I would've suggested it for is a GURL, so that I can do something like this:
Cow<GURL> request_url = ...; // some const GURL& on the RHS
if (my_condition) {
request_url = Cow::Owned(some_transformation(request_url));
}
// Now use request_url as usual
Instead of doing:
const GURL* request_url = &some_url;
GURL transformed_url;
if (my_condition) {
transformed_url = some_transformation(*request_url);
request_url = &transformed_url;
}
// Now use request_url as usual
The goal is just to minimize work in the common case where my_condition is false; and to nicely encapsulate the lifetime concerns introduced by using a raw pointer in the current approach.
The text was updated successfully, but these errors were encountered:
Clone-on-write lets you store a reference but on write it can convert to an owned version of the same type.
std.rs/cow
To work with it as an lvalue more, and avoid template writing, we may want to add a method or two:
set_owned()
Context and use case: https://chromium.slack.com/archives/CGGPN5GDT/p1698242024888729?thread_ts=1698166154.431099&cid=CGGPN5GDT
The text was updated successfully, but these errors were encountered: