mirror of
https://github.com/denoland/rusty_v8.git
synced 2024-12-26 00:59:28 -05:00
fix: don't allocate for zero-length strings (#1309)
This commit is contained in:
parent
aa203e032c
commit
987d520221
1 changed files with 14 additions and 2 deletions
|
@ -552,9 +552,15 @@ impl String {
|
|||
&self,
|
||||
scope: &mut Isolate,
|
||||
) -> std::string::String {
|
||||
let len_utf8 = self.utf8_length(scope);
|
||||
let len_utf16 = self.length();
|
||||
|
||||
// No need to allocate or do any work for zero-length strings
|
||||
if len_utf16 == 0 {
|
||||
return std::string::String::new();
|
||||
}
|
||||
|
||||
let len_utf8 = self.utf8_length(scope);
|
||||
|
||||
// If len_utf8 == len_utf16 and the string is one-byte, we can take the fast memcpy path. This is true iff the
|
||||
// string is 100% 7-bit ASCII.
|
||||
if self.is_onebyte() && len_utf8 == len_utf16 {
|
||||
|
@ -612,9 +618,15 @@ impl String {
|
|||
scope: &mut Isolate,
|
||||
buffer: &'a mut [MaybeUninit<u8>; N],
|
||||
) -> Cow<'a, str> {
|
||||
let len_utf16 = self.length();
|
||||
|
||||
// No need to allocate or do any work for zero-length strings
|
||||
if len_utf16 == 0 {
|
||||
return "".into();
|
||||
}
|
||||
|
||||
// TODO(mmastrac): Ideally we should be able to access the string's internal representation
|
||||
let len_utf8 = self.utf8_length(scope);
|
||||
let len_utf16 = self.length();
|
||||
|
||||
// If len_utf8 == len_utf16 and the string is one-byte, we can take the fast memcpy path. This is true iff the
|
||||
// string is 100% 7-bit ASCII.
|
||||
|
|
Loading…
Reference in a new issue