aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormlugg <mlugg@mlugg.co.uk>2025-02-05 19:56:43 +0000
committermlugg <mlugg@mlugg.co.uk>2025-02-05 19:56:43 +0000
commit9ba9f457be13c0c32981e94cf75ba7ea6619d92f (patch)
tree5908f90027db6a17b3099e44e5c4df4c80bab8c2
parentfbe0ae4fd4128a3652071b4b5985d68ae56e9992 (diff)
downloadzig-9ba9f457be13c0c32981e94cf75ba7ea6619d92f.tar.gz
zig-9ba9f457be13c0c32981e94cf75ba7ea6619d92f.zip
Sema: add fast path to PTR when all types are the same
I have no idea why I didn't add this when I first implemented this PTR logic.
-rw-r--r--src/Sema.zig11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index 97e90da92e..9dc7755a10 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -33930,6 +33930,17 @@ fn resolvePeerTypes(
else => {},
}
+ // Fast path: check if everything has the same type to bypass the main PTR logic.
+ same_type: {
+ const ty = sema.typeOf(instructions[0]);
+ for (instructions[1..]) |inst| {
+ if (sema.typeOf(inst).toIntern() != ty.toIntern()) {
+ break :same_type;
+ }
+ }
+ return ty;
+ }
+
const peer_tys = try sema.arena.alloc(?Type, instructions.len);
const peer_vals = try sema.arena.alloc(?Value, instructions.len);