aboutsummaryrefslogtreecommitdiff
path: root/src/string_immutable.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/string_immutable.zig')
-rw-r--r--src/string_immutable.zig25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/string_immutable.zig b/src/string_immutable.zig
index a5e3e7104..7e9895a42 100644
--- a/src/string_immutable.zig
+++ b/src/string_immutable.zig
@@ -709,6 +709,31 @@ pub inline fn copyU8IntoU16(output_: []u16, input_: []const u8) void {
}
}
+pub inline fn appendUTF8MachineWordToUTF16MachineWordUnaligned(comptime alignment: u21, output: *align(alignment) [@sizeOf(usize) / 2]u16, input: *const [@sizeOf(usize) / 2]u8) void {
+ comptime var i: usize = 0;
+ inline while (i < @sizeOf(usize) / 2) : (i += 1) {
+ output[i] = input[i];
+ }
+}
+
+pub fn copyU8IntoU16WithAlignment(comptime alignment: u21, output_: []align(alignment) u16, input_: []const u8) void {
+ var output = output_;
+ var input = input_;
+ const word = @sizeOf(usize) / 2;
+ if (comptime Environment.allow_assert) {
+ std.debug.assert(input.len <= output.len);
+ }
+ while (input.len >= word) {
+ appendUTF8MachineWordToUTF16MachineWordUnaligned(alignment, output[0..word], input[0..word]);
+ output = output[word..];
+ input = input[word..];
+ }
+
+ for (input) |c, i| {
+ output[i] = c;
+ }
+}
+
// pub inline fn copy(output_: []u8, input_: []const u8) void {
// var output = output_;
// var input = input_;