From 11d9686a3a5cf8b8c457b7bbcbe1072704a77b67 Mon Sep 17 00:00:00 2001 From: vczh Date: Wed, 10 Jun 2026 21:06:59 -0700 Subject: [PATCH] Sync copilot knowledge base --- .github/KnowledgeBase/Learning.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/KnowledgeBase/Learning.md b/.github/KnowledgeBase/Learning.md index 313621d5..0dc1c901 100644 --- a/.github/KnowledgeBase/Learning.md +++ b/.github/KnowledgeBase/Learning.md @@ -26,6 +26,7 @@ - Use `Variant::Index()` to check active alternative [1] - Avoid references into containers when mutating them [1] - Prefer designated initializers for aggregate-like structs [1] +- Prefer raw pointers unless shared ownership is required [1] - Construct `Nullable` explicitly in function calls [1] - Sort serialization metadata by deterministic keys, not pointer addresses [1] - Start async callbacks after most-derived construction [1] @@ -152,6 +153,10 @@ When iterating a container and performing mutations like `Remove()`/`Add()`, avo For small structs used as value objects (especially those with default member initializers), prefer designated initializers like `{ .field = value }` for clarity and to avoid compile-time issues from positional aggregate initialization. +## Prefer raw pointers unless shared ownership is required + +When passing an object without transferring or extending ownership, prefer a raw pointer parameter over constructing `Ptr` only to adapt the call. Reserve `Ptr` for APIs that need shared ownership, lifetime extension, or storage in shared-pointer-managed state. + ## Construct `Nullable` explicitly in function calls When passing string literals to a function parameter typed as `Nullable`, wrap them in `WString(...)` (or otherwise construct a `WString`) to make the conversion explicit. Direct assignment to a `Nullable` field may compile via an assignment operator, but function-call argument conversion can require explicit construction.