Add comment explaining why unsafe is used

This commit is contained in:
Elara 2023-01-24 01:31:13 -08:00
parent eb6d70bc26
commit bab7ffe22b

View File

@ -266,6 +266,11 @@ func joinAll(c *lemmy.WSClient) {
} }
} }
// toSubmatches converts matches coming from PCRE2 to a
// submatch array used for the template
func toSubmatches(s [][]string) []Submatches { func toSubmatches(s [][]string) []Submatches {
// Unfortunately, Go doesn't allow for this conversion
// even though the memory layout is identical and it's
// safe, so it is done using unsafe pointer magic
return *(*[]Submatches)(unsafe.Pointer(&s)) return *(*[]Submatches)(unsafe.Pointer(&s))
} }