Bug 1897607 - Inline StringBuffer assignment. r=smaug

I wrote this while investigating bug 1896729. It seems it didn't help
with those, but helps with other micro-benchmarks (plus it's not a lot
of code so seems worth inlining):

https://treeherder.mozilla.org/perfherder/comparesubtest?originalProject=try&newProject=try&newRevision=27ba5b2ad99b0e7dc5af443ee21f0f227f9a7589&originalSignature=4765498&newSignature=4765498&framework=1&application=firefox&originalRevision=63f02a17fab2cf51723bc45088c76a5ecde37af9&page=1&showOnlyImportant=1

Differential Revision: https://phabricator.services.mozilla.com/D210876
This commit is contained in:
Emilio Cobos Álvarez 2024-05-18 17:33:20 +00:00
parent 060c48abc9
commit 8707f8b350
2 changed files with 8 additions and 12 deletions

View file

@ -404,17 +404,6 @@ void nsTSubstring<T>::Assign(const char_type* aData, size_type aLength) {
}
}
template <typename T>
void nsTSubstring<T>::Assign(already_AddRefed<mozilla::StringBuffer> aBuffer,
size_type aLength) {
mozilla::StringBuffer* buffer = aBuffer.take();
auto* data = reinterpret_cast<char_type*>(buffer->Data());
MOZ_DIAGNOSTIC_ASSERT(data[aLength] == char_type(0),
"data should be null terminated");
Finalize();
SetData(data, aLength, DataFlags::REFCOUNTED | DataFlags::TERMINATED);
}
template <typename T>
bool nsTSubstring<T>::Assign(const char_type* aData,
const fallible_t& aFallible) {

View file

@ -422,7 +422,14 @@ class nsTSubstring : public mozilla::detail::nsTStringRepr<T> {
Assign(already_AddRefed<mozilla::StringBuffer>(aBuffer), aLength);
}
void NS_FASTCALL Assign(already_AddRefed<mozilla::StringBuffer> aBuffer,
size_type aLength);
size_type aLength) {
mozilla::StringBuffer* buffer = aBuffer.take();
auto* data = reinterpret_cast<char_type*>(buffer->Data());
MOZ_DIAGNOSTIC_ASSERT(data[aLength] == char_type(0),
"data should be null terminated");
Finalize();
SetData(data, aLength, DataFlags::REFCOUNTED | DataFlags::TERMINATED);
}
#if defined(MOZ_USE_CHAR16_WRAPPER)
template <typename Q = T, typename EnableIfChar16 = mozilla::Char16OnlyT<Q>>