internal/core/adt: avoid allocations in matchPattern master
Feature.ToValue was called eagerly for every string label before pattern matching, allocating a *String even though the fast path only needs the string content. This change retrieves the string directly via ctx.IndexToString for fast-path cases, only allocating in the slow path. This also fixes a bug in jsonschema where error patterns were not handled correctly. The old code checked `!k.IsAnyOf(pattern.Kind())` before the switch statement, but *Bottom has Kind() == BottomKind (0), so this check always failed for error patterns, returning false before the *Bottom case could be reached. The new code handles *Bottom in the switch before any Kind filtering occurs. The bug fix cannot be easily separated from the optimization because both changes affect how pattern matching flows through the code, and attempts to isolate the fix while keeping the old allocation behavior were unsuccessful. │ old │ new │ │ B/op │ B/op vs base │ VetInventory 4.592Gi ± ∞ ¹ 4.565Gi ± ∞ ¹ -0.58% (p=1.000 n=1) │ old │ new │ │ allocs/op │ allocs/op vs base │ VetInventory 47.89M ± ∞ ¹ 47.29M ± ∞ ¹ -1.26% (p=1.000 n=1) Signed-off-by: Daniel Martí <mvdan@mvdan.cc> Change-Id: I2c815823ff2412e32f1fbc967c847bed3101291b Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1229642 TryBot-Result: CUEcueckoo <cueckoo@cuelang.org> Reviewed-by: Matthew Sackman <matthew@cue.works> Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>