diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2016-07-12 14:19:09 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2016-07-14 03:58:57 +0000 |
commit | be491913c036b148cd4f90fa0132e269a507dbad (patch) | |
tree | 5e88a35531f162c5bd2d7f4e31a06cf4135212d5 /src/qml/compiler/qv4compiler.cpp | |
parent | 8dc7cb73ffdcd50fbbe2a1bc74a06b79092db4d8 (diff) |
Fix endian support in compiled data structures
The goal is to make the compiled data structures persistent on disk. In order
to make it possible to create these data structures on a "host" system that may
have a different endianness than the target system, we now make all the word
sized fields little-endian. The template wrappers from QJson provide
zero-overhead access for little-endian machines (the vast majority) while
maintaining a large degree of source compatibility.
Change-Id: I3d30da1fcf3bffb98dbe9337d3a35482fb7b57c8
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/qml/compiler/qv4compiler.cpp')
-rw-r--r-- | src/qml/compiler/qv4compiler.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/qml/compiler/qv4compiler.cpp b/src/qml/compiler/qv4compiler.cpp index 55d2501024..8499f9b9aa 100644 --- a/src/qml/compiler/qv4compiler.cpp +++ b/src/qml/compiler/qv4compiler.cpp @@ -83,7 +83,13 @@ void QV4::Compiler::StringTableGenerator::serialize(CompiledData::Unit *unit) QV4::CompiledData::String *s = (QV4::CompiledData::String*)(stringData); s->size = qstr.length(); +#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN memcpy(s + 1, qstr.constData(), qstr.length()*sizeof(ushort)); +#else + ushort *uc = reinterpret_cast<ushort *>(s + 1); + for (int i = 0; i < qstr.length(); ++i) + uc[i] = qToLittleEndian<ushort>(qstr.at(i).unicode()); +#endif stringData += QV4::CompiledData::String::calculateSize(qstr); } |