googleapis / googleapis/google-cloud-cpp

Optimize initial `OptionSpan`

Aperta
#12,411 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub
next major: breaking change type: cleanup
Lingua principale
C++
Stelle
659
Fork
462
Merge medio
1g 2h
PR unite (30g)
89

Descrizione

Every request in a `*Client` starts with something like:

```cc
google::cloud::internal::OptionsSpan span(std::move(options), options_);
```

The `options_` member variable never changes value. We should avoid the implicit copy from these options. If we can hold them as a `std::shared_ptr` then maybe `ImmutableOptions` can become a class that holds two `Options`, one by value (initialized via move) and a `std::shared_ptr<>` with the remaining values.

Something like:

```cc
class internal::OptionsImpl { // Similar to the Options class today
public:
template auto get() const { ... }
// has() and get() rolled into a single operation.
template std::pair find() const { ... }
};

class internal::ImmutableOptions {
public:
template auto get() const {
auto [has, value] = impl_.find();
if (has) return *value;
return fallback_.get();
}

// No set or unset member functions.

private:
OptionsImpl impl_;
std::shared_ptr fallback_;
};

class Options {

private:
OptionsImpl impl_;
};

```

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.