Skip to content

Commit

Permalink
[Impeller] dont allocate capture strings in release mode. (flutter#48760
Browse files Browse the repository at this point in the history
)

I'm not exactly sure why, but this seems to stop the allocation of capture labels in release mode.

Fixes flutter/flutter#138908
  • Loading branch information
jonahwilliams authored Dec 8, 2023
1 parent 7dc51b8 commit e9cb19f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
6 changes: 3 additions & 3 deletions impeller/core/capture.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,16 @@ void Capture::Rewind() {
#ifdef IMPELLER_ENABLE_CAPTURE
#define _CAPTURE_PROPERTY_RECORDER_DEFINITION(type_name, pascal_name, \
lower_name) \
type_name Capture::Add##pascal_name(const std::string& label, \
type_name value, \
type_name Capture::Add##pascal_name(std::string_view label, type_name value, \
CaptureProperty::Options options) { \
if (!active_) { \
return value; \
} \
FML_DCHECK(element_ != nullptr); \
\
std::string label_clone = std::string(label); \
auto new_value = Capture##pascal_name##Property::Make( \
label, std::move(value), options); \
label_clone, std::move(value), options); \
\
auto next = std::reinterpret_pointer_cast<Capture##pascal_name##Property>( \
element_->properties.GetNext(std::move(new_value), options.readonly)); \
Expand Down
21 changes: 11 additions & 10 deletions impeller/core/capture.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,16 +214,16 @@ struct CaptureElement final : public CaptureCursorListElement<CaptureElement> {
};

#ifdef IMPELLER_ENABLE_CAPTURE
#define _CAPTURE_PROPERTY_RECORDER_DECLARATION(type_name, pascal_name, \
lower_name) \
type_name Add##pascal_name(const std::string& label, type_name value, \
#define _CAPTURE_PROPERTY_RECORDER_DECLARATION(type_name, pascal_name, \
lower_name) \
type_name Add##pascal_name(std::string_view label, type_name value, \
CaptureProperty::Options options = {});
#else
#define _CAPTURE_PROPERTY_RECORDER_DECLARATION(type_name, pascal_name, \
lower_name) \
inline type_name Add##pascal_name(const std::string& label, type_name value, \
CaptureProperty::Options options = {}) { \
return value; \
#define _CAPTURE_PROPERTY_RECORDER_DECLARATION(type_name, pascal_name, \
lower_name) \
inline type_name Add##pascal_name(std::string_view label, type_name value, \
CaptureProperty::Options options = {}) { \
return value; \
}
#endif

Expand All @@ -235,13 +235,14 @@ class Capture {

static Capture MakeInactive();

inline Capture CreateChild(const std::string& label) {
inline Capture CreateChild(std::string_view label) {
#ifdef IMPELLER_ENABLE_CAPTURE
if (!active_) {
return Capture();
}

auto new_capture = Capture(label);
std::string label_copy = std::string(label);
auto new_capture = Capture(label_copy);
new_capture.element_ =
element_->children.GetNext(new_capture.element_, false);
new_capture.element_->Rewind();
Expand Down

0 comments on commit e9cb19f

Please sign in to comment.