#Is there a cost to converting from []u8 to Vector?

1 messages · Page 1 of 1 (latest)

woven jay
#

I have some strings in a large dataset that may or may not have a # character. The # character is a comment character similar to how comments are written in POSIX shell.

I wanna convert the []u8 to Vector so I can utilize SIMD instructions which are faster than normal character comparison.

warped olive
#

arrays and vectors coerce into each other ([n]T <-> @Vector(n, T)).
you can reslice your slice with comptime-known bounds to get a pointer to an array, dereference that, and coerce

#

there shouldn't be much overhead, I don't think, since the whole conversion amounts into an unaligned load into a SIMD register - you can go to Compiler Explorer to see the generated assembly, and make sure to run performance tests, if you're worried about that