[ox/preloader] Make Preloader use small string section of strings when able

This commit is contained in:
Gary Talent 2022-12-03 16:32:56 -06:00
parent 86cbf66699
commit 3040e6c90a

View File

@ -175,15 +175,20 @@ constexpr ox::Error Preloader<PlatSpec>::field(CRStringView, const ox::BasicStri
} }
using VecMap = ox::VectorMemMap<PlatSpec>; using VecMap = ox::VectorMemMap<PlatSpec>;
const auto sz = val->bytes(); const auto sz = val->bytes();
oxRequire(a, ox::allocate(&m_writer, sz)); VecMap vecVal{
const VecMap vecVal{
.smallVecSize = SmallStringSize, .smallVecSize = SmallStringSize,
.size = PlatSpec::correctEndianness(static_cast<typename PlatSpec::size_t>(sz)), .size = PlatSpec::correctEndianness(static_cast<typename PlatSpec::size_t>(sz)),
.cap = PlatSpec::correctEndianness(static_cast<typename PlatSpec::size_t>(sz)), .cap = PlatSpec::correctEndianness(static_cast<typename PlatSpec::size_t>(sz)),
.items = sz ? PlatSpec::correctEndianness(static_cast<typename PlatSpec::size_t>(a) + PlatSpec::RomStart) : 0,
}; };
oxReturnError(pad(&vecVal)); oxReturnError(pad(&vecVal));
const auto restore = m_writer.tellp(); const auto restore = m_writer.tellp();
std::size_t a = 0;
if (sz && sz >= SmallStringSize) {
oxReturnError(ox::allocate(&m_writer, sz).moveTo(&a));
} else {
a = restore;
}
vecVal.items = sz ? PlatSpec::correctEndianness(static_cast<typename PlatSpec::size_t>(a) + PlatSpec::RomStart) : 0;
oxReturnError(m_writer.seekp(a)); oxReturnError(m_writer.seekp(a));
oxReturnError(m_writer.write(val->data(), sz)); oxReturnError(m_writer.write(val->data(), sz));
oxReturnError(m_writer.seekp(restore)); oxReturnError(m_writer.seekp(restore));