diff options
-rw-r--r-- | docs/dev/style.md | 7 | ||||
-rw-r--r-- | editors/code/src/inlay_hints.ts | 6 |
2 files changed, 11 insertions, 2 deletions
diff --git a/docs/dev/style.md b/docs/dev/style.md index 435de63e3..20f1b6253 100644 --- a/docs/dev/style.md +++ b/docs/dev/style.md | |||
@@ -248,6 +248,8 @@ fn frbonicate(f: impl AsRef<Path>) { | |||
248 | 248 | ||
249 | # Premature Pessimization | 249 | # Premature Pessimization |
250 | 250 | ||
251 | ## Avoid Allocations | ||
252 | |||
251 | Avoid writing code which is slower than it needs to be. | 253 | Avoid writing code which is slower than it needs to be. |
252 | Don't allocate a `Vec` where an iterator would do, don't allocate strings needlessly. | 254 | Don't allocate a `Vec` where an iterator would do, don't allocate strings needlessly. |
253 | 255 | ||
@@ -267,6 +269,8 @@ if words.len() != 2 { | |||
267 | } | 269 | } |
268 | ``` | 270 | ``` |
269 | 271 | ||
272 | ## Push Allocations to the Call Site | ||
273 | |||
270 | If allocation is inevitable, let the caller allocate the resource: | 274 | If allocation is inevitable, let the caller allocate the resource: |
271 | 275 | ||
272 | ```rust | 276 | ```rust |
@@ -282,6 +286,9 @@ fn frobnicate(s: &str) { | |||
282 | } | 286 | } |
283 | ``` | 287 | ``` |
284 | 288 | ||
289 | This is better because it reveals the costs. | ||
290 | It is also more efficient when the caller already owns the allocation. | ||
291 | |||
285 | ## Collection types | 292 | ## Collection types |
286 | 293 | ||
287 | Prefer `rustc_hash::FxHashMap` and `rustc_hash::FxHashSet` instead of the ones in `std::collections`. | 294 | Prefer `rustc_hash::FxHashMap` and `rustc_hash::FxHashSet` instead of the ones in `std::collections`. |
diff --git a/editors/code/src/inlay_hints.ts b/editors/code/src/inlay_hints.ts index 30ade9b98..ed0db2924 100644 --- a/editors/code/src/inlay_hints.ts +++ b/editors/code/src/inlay_hints.ts | |||
@@ -44,10 +44,12 @@ const paramHints = createHintStyle("parameter"); | |||
44 | const chainingHints = createHintStyle("chaining"); | 44 | const chainingHints = createHintStyle("chaining"); |
45 | 45 | ||
46 | function createHintStyle(hintKind: "type" | "parameter" | "chaining") { | 46 | function createHintStyle(hintKind: "type" | "parameter" | "chaining") { |
47 | // U+200C is a zero-width non-joiner to prevent the editor from forming a ligature | ||
48 | // between code and type hints | ||
47 | const [pos, render] = ({ | 49 | const [pos, render] = ({ |
48 | type: ["after", (label: string) => `: ${label}`], | 50 | type: ["after", (label: string) => `\u{200c}: ${label}`], |
49 | parameter: ["before", (label: string) => `${label}: `], | 51 | parameter: ["before", (label: string) => `${label}: `], |
50 | chaining: ["after", (label: string) => `: ${label}`], | 52 | chaining: ["after", (label: string) => `\u{200c}: ${label}`], |
51 | } as const)[hintKind]; | 53 | } as const)[hintKind]; |
52 | 54 | ||
53 | const fg = new vscode.ThemeColor(`rust_analyzer.inlayHints.foreground.${hintKind}Hints`); | 55 | const fg = new vscode.ThemeColor(`rust_analyzer.inlayHints.foreground.${hintKind}Hints`); |