@EliasMårtenson in k, (a;b;c) is syntax to make a list with elements a, b, and c. To call a function with multiple arguments, you simply say f[a;b;c]. Which is a pretty neat unification
APL (Dyalog Extended), 23 bytes
⍎⌽('!(\d.*)'⎕R'\1~')⍣≡⍞
Repeatedly shift any !s to the right with the fixpoint ⍣≡
!!!!0! -> !!!0!~ -> !!0!~~ -> !0!~~~ -> 0!~~~~
Then reverse with ⌽, and execute with ⍎
Try it online!
@dzaima If you find the index range ahead of time with min/max, Java might be able to vectorize that part and you can use special code if there are no negative indices.
Just compared the self-hosted compiler against ⍎ in dzaima/BQN on the compiler source (wrapped in {𝕩⋄…} so nothing actually executes) and it's only a factor of 3-4 difference now.
(my compiler uses linked lists and multiple temporary objects per token, but then again my runtime could be sped up multiple times in a language more suitable for it)
@Marshall i somewhat doubt it'd be able to utilize the calculated min/max, but maybe res[i] = xi[Math.max(0, Math.min(c, xi.length))]; would be an improvement anyways; i'll test later
@rak1507 {1-⍨≢{⍵⊇⍨⍸2=/⍵}⍡{⍵≡⍬}⍵} seems to output things in TIO
@dzaima I guess Java will still do its own bounds checking on x[c], but unless it knows how to merge those with your checks that cost is the same either way.
@Bubbler Yes, assignments can clash, because n+←1 becomes n plus+←1. I should maybe make extended insert ∘⊢ to the right of all names. That'll also fix the 1+n←2 becoming 1 plus n←2 issue.