From f1a3137b411f4bd1df96b77badd7a503b7fa471a Mon Sep 17 00:00:00 2001 From: David Aurelio Date: Tue, 29 Jan 2019 10:30:11 -0800 Subject: [PATCH] Add `MarkerSection` Summary: @public Adds a class for triggering markers. This calls `startMarker()` on construction, and `endMarker()` on destruction, thus being usable like a "scope guard": the object is instantiated, and automatically destroyed when going out of scope. Reviewed By: SidharthGuglani Differential Revision: D13817589 fbshipit-source-id: fd88884af970c1c0933d9ca6843f3f8f5d28b9e6 --- React/React.xcodeproj/project.pbxproj | 8 +++++ ReactCommon/yoga/yoga/YGMarker.h | 22 +++++++++++++ ReactCommon/yoga/yoga/instrumentation.h | 44 +++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 ReactCommon/yoga/yoga/instrumentation.h diff --git a/React/React.xcodeproj/project.pbxproj b/React/React.xcodeproj/project.pbxproj index 317ec5dc3..29652f1e2 100644 --- a/React/React.xcodeproj/project.pbxproj +++ b/React/React.xcodeproj/project.pbxproj @@ -1074,6 +1074,9 @@ AC4A6AF921FB4EA900FBEC39 /* YGMarker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AC4A6AF821FB4EA900FBEC39 /* YGMarker.cpp */; }; AC4A6AFA21FB4EBF00FBEC39 /* YGMarker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AC4A6AF821FB4EA900FBEC39 /* YGMarker.cpp */; }; AC4A6AFB21FB4ECA00FBEC39 /* YGMarker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AC4A6AF821FB4EA900FBEC39 /* YGMarker.cpp */; }; + AC52CEDE21FB3FF9003C6BEC /* instrumentation.h in Headers */ = {isa = PBXBuildFile; fileRef = AC52CEDD21FB3FF9003C6BEC /* instrumentation.h */; }; + AC52CEDF21FB401D003C6BEC /* instrumentation.h in Headers */ = {isa = PBXBuildFile; fileRef = AC52CEDD21FB3FF9003C6BEC /* instrumentation.h */; }; + AC52CEE021FB403B003C6BEC /* instrumentation.h in Headers */ = {isa = PBXBuildFile; fileRef = AC52CEDD21FB3FF9003C6BEC /* instrumentation.h */; }; AC6B69E321B1467C00B2B68A /* YGValue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AC6B69E121B1467C00B2B68A /* YGValue.cpp */; }; AC6B69E421B1467C00B2B68A /* YGValue.h in Headers */ = {isa = PBXBuildFile; fileRef = AC6B69E221B1467C00B2B68A /* YGValue.h */; }; AC6B69E521B1469A00B2B68A /* YGValue.h in Headers */ = {isa = PBXBuildFile; fileRef = AC6B69E221B1467C00B2B68A /* YGValue.h */; }; @@ -2236,6 +2239,7 @@ A2440AA01DF8D854006E7BFC /* RCTReloadCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTReloadCommand.h; sourceTree = ""; }; A2440AA11DF8D854006E7BFC /* RCTReloadCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTReloadCommand.m; sourceTree = ""; }; AC4A6AF821FB4EA900FBEC39 /* YGMarker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = YGMarker.cpp; sourceTree = ""; }; + AC52CEDD21FB3FF9003C6BEC /* instrumentation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = instrumentation.h; sourceTree = ""; }; AC6B69E121B1467C00B2B68A /* YGValue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = YGValue.cpp; sourceTree = ""; }; AC6B69E221B1467C00B2B68A /* YGValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YGValue.h; sourceTree = ""; }; AC70D2E81DE489E4002E6351 /* RCTJavaScriptLoader.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RCTJavaScriptLoader.mm; sourceTree = ""; }; @@ -2365,6 +2369,7 @@ isa = PBXGroup; children = ( AC4A6AF821FB4EA900FBEC39 /* YGMarker.cpp */, + AC52CEDD21FB3FF9003C6BEC /* instrumentation.h */, AC90463D21C91CC2005B24B3 /* CompactValue.h */, AC6B69E121B1467C00B2B68A /* YGValue.cpp */, AC6B69E221B1467C00B2B68A /* YGValue.h */, @@ -3297,6 +3302,7 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( + AC52CEE021FB403B003C6BEC /* instrumentation.h in Headers */, AC90463F21C91D02005B24B3 /* CompactValue.h in Headers */, AC6B69E821B146C500B2B68A /* YGValue.h in Headers */, AC8360D221B025EF00FC46B9 /* YGConfig.h in Headers */, @@ -3362,6 +3368,7 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( + AC52CEDF21FB401D003C6BEC /* instrumentation.h in Headers */, AC90464021C91D14005B24B3 /* CompactValue.h in Headers */, AC6B69E521B1469A00B2B68A /* YGValue.h in Headers */, AC8360CF21B0258B00FC46B9 /* YGConfig.h in Headers */, @@ -3506,6 +3513,7 @@ AC6B69E421B1467C00B2B68A /* YGValue.h in Headers */, 3D80DA571DF820620028D040 /* RCTSourceCode.h in Headers */, EBF21BBC1FC498270052F4D5 /* InspectorInterfaces.h in Headers */, + AC52CEDE21FB3FF9003C6BEC /* instrumentation.h in Headers */, 3D80DA581DF820620028D040 /* RCTStatusBarManager.h in Headers */, 3D80DA591DF820620028D040 /* RCTTiming.h in Headers */, 3D80DA5A1DF820620028D040 /* RCTUIManager.h in Headers */, diff --git a/ReactCommon/yoga/yoga/YGMarker.h b/ReactCommon/yoga/yoga/YGMarker.h index 28fc3fff5..f7da1b58a 100644 --- a/ReactCommon/yoga/yoga/YGMarker.h +++ b/ReactCommon/yoga/yoga/YGMarker.h @@ -37,3 +37,25 @@ typedef struct { void YGConfigSetMarkerCallbacks(YGConfigRef, YGMarkerCallbacks); YG_EXTERN_C_END + +#ifdef __cplusplus + +namespace facebook { +namespace yoga { +namespace marker { +namespace detail { + +template +struct MarkerData; + +template <> +struct MarkerData { + using type = YGMarkerLayoutData; +}; + +} // namespace detail +} // namespace marker +} // namespace yoga +} // namespace facebook + +#endif // __cplusplus diff --git a/ReactCommon/yoga/yoga/instrumentation.h b/ReactCommon/yoga/yoga/instrumentation.h new file mode 100644 index 000000000..670fc2bda --- /dev/null +++ b/ReactCommon/yoga/yoga/instrumentation.h @@ -0,0 +1,44 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the LICENSE + * file in the root directory of this source tree. + */ +#include "YGConfig.h" +#include "YGMarker.h" +#include "YGNode.h" + +namespace facebook { +namespace yoga { +namespace marker { + +template +class MarkerSection { +public: + MarkerSection(YGNodeRef node) : MarkerSection{node, node->getConfig()} {} + ~MarkerSection() { + if (endMarker_) { + endMarker_(MarkerType, node_, {&data}, userData_); + } + } + + typename detail::MarkerData::type data = {}; + +private: + decltype(YGMarkerCallbacks{}.endMarker) endMarker_; + YGNodeRef node_; + void* userData_; + + MarkerSection(YGNodeRef node, YGConfigRef config) + : MarkerSection{node, config ? &config->markerCallbacks : nullptr} {} + MarkerSection(YGNodeRef node, YGMarkerCallbacks* callbacks) + : endMarker_{callbacks ? callbacks->endMarker : nullptr}, + node_{node}, + userData_{callbacks && callbacks->startMarker + ? callbacks->startMarker(MarkerType, node, {&data}) + : nullptr} {} +}; + +} // namespace marker +} // namespace yoga +} // namespace facebook