Skip to content

Commit 492d32c

Browse files
committed
use std for inputs < 64 bytes in cases where runtime dispatch is not used
1 parent a6ce7cf commit 492d32c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/implementation/x86/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ fn get_fastest_available_implementation_basic() -> super::ValidateUtf8Fn {
5050
pub(crate) unsafe fn validate_utf8_basic(
5151
input: &[u8],
5252
) -> core::result::Result<(), crate::basic::Utf8Error> {
53+
if input.len() < 64 {
54+
return super::validate_utf8_basic_fallback(input);
55+
}
56+
5357
avx2::validate_utf8_basic(input)
5458
}
5559

@@ -61,6 +65,10 @@ pub(crate) unsafe fn validate_utf8_basic(
6165
pub(crate) unsafe fn validate_utf8_basic(
6266
input: &[u8],
6367
) -> core::result::Result<(), crate::basic::Utf8Error> {
68+
if input.len() < 64 {
69+
return super::validate_utf8_basic_fallback(input);
70+
}
71+
6472
sse42::validate_utf8_basic(input)
6573
}
6674

@@ -118,6 +126,10 @@ fn get_fastest_available_implementation_compat() -> super::ValidateUtf8CompatFn
118126
pub(crate) unsafe fn validate_utf8_compat(
119127
input: &[u8],
120128
) -> core::result::Result<(), crate::compat::Utf8Error> {
129+
if input.len() < 64 {
130+
return super::validate_utf8_compat_fallback(input);
131+
}
132+
121133
avx2::validate_utf8_compat(input)
122134
}
123135

@@ -129,6 +141,10 @@ pub(crate) unsafe fn validate_utf8_compat(
129141
pub(crate) unsafe fn validate_utf8_compat(
130142
input: &[u8],
131143
) -> core::result::Result<(), crate::compat::Utf8Error> {
144+
if input.len() < 64 {
145+
return super::validate_utf8_compat_fallback(input);
146+
}
147+
132148
sse42::validate_utf8_compat(input)
133149
}
134150

0 commit comments

Comments
 (0)