forked from organicmaps/organicmaps
Review fixes.
This commit is contained in:
parent
ea3407d1ec
commit
e78e3f6fdc
11 changed files with 28 additions and 26 deletions
|
@ -8,11 +8,14 @@
|
|||
|
||||
// #define ENDIAN_IS_BIG
|
||||
|
||||
// @TODO(bykoianko) This method returns false since 05.12.2010. That means only little endian
|
||||
// architecture is supported. Now checks are added to generator and to app that only
|
||||
// little endian architecture is supported. All the usage of IsBigEndian(), ReverseByteOrder()
|
||||
// and SwapIfBigEndian() should be removed.
|
||||
inline bool IsBigEndian()
|
||||
// @TODO(bykoianko) This method returns false since 05.12.2010. That means only little-endian
|
||||
// architectures are supported. When it's necessary to support a big-endian system:
|
||||
// * method IsBigEndianMacroBased() should be implemented based on IsLittleEndian() function
|
||||
// * method SwapIfBigEndianMacroBased() should be implemented based on IsLittleEndian() function
|
||||
// * all serialization and deserialization of rs_bit_vector and the other rank-select structures
|
||||
// should be implemented taking endianness into account
|
||||
|
||||
inline bool IsBigEndianMacroBased()
|
||||
{
|
||||
#ifdef ENDIAN_IS_BIG
|
||||
return true;
|
||||
|
@ -33,7 +36,7 @@ template <typename T> T ReverseByteOrder(T t)
|
|||
return res;
|
||||
}
|
||||
|
||||
template <typename T> inline T SwapIfBigEndian(T t)
|
||||
template <typename T> inline T SwapIfBigEndianMacroBased(T t)
|
||||
{
|
||||
#ifdef ENDIAN_IS_BIG
|
||||
return ReverseByteOrder(t);
|
||||
|
@ -45,6 +48,6 @@ template <typename T> inline T SwapIfBigEndian(T t)
|
|||
inline bool IsLittleEndian()
|
||||
{
|
||||
uint16_t const word = 0x0001;
|
||||
char const * const b = reinterpret_cast<char const * const>(&word);
|
||||
return b[0] == 0x1;
|
||||
uint8_t const * const b = reinterpret_cast<uint8_t const * const>(&word);
|
||||
return b[0] != 0x0;
|
||||
}
|
||||
|
|
|
@ -264,7 +264,7 @@ inline TPrimitive ReadPrimitiveFromPos(TReader const & reader, uint64_t pos)
|
|||
#endif
|
||||
TPrimitive primitive;
|
||||
ReadFromPos(reader, pos, &primitive, sizeof(primitive));
|
||||
return SwapIfBigEndian(primitive);
|
||||
return SwapIfBigEndianMacroBased(primitive);
|
||||
}
|
||||
|
||||
template <typename TPrimitive, class TSource>
|
||||
|
@ -275,7 +275,7 @@ TPrimitive ReadPrimitiveFromSource(TSource & source)
|
|||
#endif
|
||||
TPrimitive primitive;
|
||||
source.Read(&primitive, sizeof(primitive));
|
||||
return SwapIfBigEndian(primitive);
|
||||
return SwapIfBigEndianMacroBased(primitive);
|
||||
}
|
||||
|
||||
template <typename TPrimitive, typename TSource>
|
||||
|
|
|
@ -9,7 +9,7 @@ template <class Sink, typename T>
|
|||
std::enable_if_t<std::is_integral<T>::value || std::is_enum<T>::value, void> WriteToSink(
|
||||
Sink & sink, T const & v)
|
||||
{
|
||||
T const t = SwapIfBigEndian(v);
|
||||
T const t = SwapIfBigEndianMacroBased(v);
|
||||
sink.Write(&t, sizeof(T));
|
||||
}
|
||||
|
||||
|
|
|
@ -168,7 +168,7 @@ using namespace generator;
|
|||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
CHECK(IsLittleEndian(), ("Only little endian architecture is supported."));
|
||||
CHECK(IsLittleEndian(), ("Only little-endian architectures are supported."));
|
||||
|
||||
google::SetUsageMessage(
|
||||
"Takes OSM XML data from stdin and creates data and index files in several passes.");
|
||||
|
|
|
@ -189,7 +189,7 @@ private:
|
|||
if (!m_header.IsValid())
|
||||
return false;
|
||||
|
||||
bool const isHostBigEndian = IsBigEndian();
|
||||
bool const isHostBigEndian = IsBigEndianMacroBased();
|
||||
bool const isDataBigEndian = m_header.m_base.m_endianness == 1;
|
||||
bool const endiannesMismatch = isHostBigEndian != isDataBigEndian;
|
||||
|
||||
|
@ -332,6 +332,7 @@ void CentersTableBuilder::Freeze(Writer & writer) const
|
|||
auto const endOffset = writer.Pos();
|
||||
|
||||
writer.Seek(startOffset);
|
||||
CHECK_EQUAL(header.m_base.m_endianness, 0, ("|m_endianness| should be set to little-endian."));
|
||||
header.Write(writer);
|
||||
writer.Seek(endOffset);
|
||||
}
|
||||
|
|
|
@ -88,7 +88,7 @@ private:
|
|||
{
|
||||
uint32_t key = 0;
|
||||
src.Read(&key, m_Header.m_LeafBytes);
|
||||
key = SwapIfBigEndian(key);
|
||||
key = SwapIfBigEndianMacroBased(key);
|
||||
if (key > end)
|
||||
break;
|
||||
value += ReadVarInt<int64_t>(src);
|
||||
|
|
|
@ -230,7 +230,7 @@ public:
|
|||
prevValue = 0;
|
||||
prevPos = writer.Pos();
|
||||
}
|
||||
uint64_t const keySerial = SwapIfBigEndian(key);
|
||||
uint64_t const keySerial = SwapIfBigEndianMacroBased(key);
|
||||
writer.Write(&keySerial, m_LeafBytes);
|
||||
WriteVarInt(writer, static_cast<int64_t>(value) - static_cast<int64_t>(prevValue));
|
||||
prevKey = key;
|
||||
|
|
|
@ -56,7 +56,7 @@ CheckResult CheckEndianness(TReader && reader)
|
|||
return CheckResult::CorruptedHeader;
|
||||
uint8_t flags;
|
||||
reader.Read(kFlagsOffset, &flags, sizeof(flags));
|
||||
bool const isHostBigEndian = IsBigEndian();
|
||||
bool const isHostBigEndian = IsBigEndianMacroBased();
|
||||
bool const isDataBigEndian = flags & 1;
|
||||
if (isHostBigEndian != isDataBigEndian)
|
||||
return CheckResult::EndiannessMismatch;
|
||||
|
@ -110,7 +110,7 @@ public:
|
|||
static uint64_t const padding = 0;
|
||||
|
||||
uint8_t const version = GetVersion();
|
||||
uint8_t const flags = preserveHostEndianness ? IsBigEndian() : !IsBigEndian();
|
||||
uint8_t const flags = preserveHostEndianness ? IsBigEndianMacroBased() : !IsBigEndianMacroBased();
|
||||
writer.Write(&version, sizeof(version));
|
||||
writer.Write(&flags, sizeof(flags));
|
||||
writer.Write(&padding, 6);
|
||||
|
|
|
@ -392,9 +392,7 @@ Framework::Framework(FrameworkParams const & params)
|
|||
, m_purchase(std::make_unique<Purchase>())
|
||||
, m_tipsApi(static_cast<TipsApi::Delegate &>(*this))
|
||||
{
|
||||
CHECK(IsLittleEndian(), ("Only little endian architecture is supported."));
|
||||
|
||||
m_startBackgroundTime = my::Timer::LocalTime();
|
||||
CHECK(IsLittleEndian(), ("Only little-endian architectures are supported."));
|
||||
|
||||
// Editor should be initialized from the main thread to set its ThreadChecker.
|
||||
// However, search calls editor upon initialization thus setting the lazy editor's ThreadChecker
|
||||
|
|
|
@ -31,7 +31,7 @@ size_t constexpr kPointSize = 8 * sizeof(double) + sizeof(uint8_t);
|
|||
template <typename T>
|
||||
void MemWrite(void * ptr, T value)
|
||||
{
|
||||
value = SwapIfBigEndian(value);
|
||||
value = SwapIfBigEndianMacroBased(value);
|
||||
memcpy(ptr, &value, sizeof(T));
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ T MemRead(void const * ptr)
|
|||
{
|
||||
T value;
|
||||
memcpy(&value, ptr, sizeof(T));
|
||||
return SwapIfBigEndian(value);
|
||||
return SwapIfBigEndianMacroBased(value);
|
||||
}
|
||||
|
||||
void Pack(char * p, location::GpsInfo const & info)
|
||||
|
@ -87,7 +87,7 @@ inline size_t GetItemCount(size_t fileSize)
|
|||
inline bool WriteVersion(fstream & f, uint32_t version)
|
||||
{
|
||||
static_assert(kHeaderSize == sizeof(version), "");
|
||||
version = SwapIfBigEndian(version);
|
||||
version = SwapIfBigEndianMacroBased(version);
|
||||
f.write(reinterpret_cast<char const *>(&version), kHeaderSize);
|
||||
return f.good();
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ inline bool ReadVersion(fstream & f, uint32_t & version)
|
|||
{
|
||||
static_assert(kHeaderSize == sizeof(version), "");
|
||||
f.read(reinterpret_cast<char *>(&version), kHeaderSize);
|
||||
version = SwapIfBigEndian(version);
|
||||
version = SwapIfBigEndianMacroBased(version);
|
||||
return f.good();
|
||||
}
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@ pair<Protocol::PacketType, size_t> Protocol::DecodeHeader(vector<uint8_t> const
|
|||
ASSERT_GREATER_OR_EQUAL(data.size(), sizeof(uint32_t /* header */), ());
|
||||
|
||||
uint32_t size = (*reinterpret_cast<uint32_t const *>(data.data())) & 0xFFFFFF00;
|
||||
if (!IsBigEndian())
|
||||
if (!IsBigEndianMacroBased())
|
||||
size = ReverseByteOrder(size);
|
||||
|
||||
return make_pair(PacketType(static_cast<uint8_t>(data[0])), size);
|
||||
|
@ -125,7 +125,7 @@ void Protocol::InitHeader(vector<uint8_t> & packet, PacketType type, uint32_t pa
|
|||
|
||||
ASSERT_LESS(size, 0x00FFFFFF, ());
|
||||
|
||||
if (!IsBigEndian())
|
||||
if (!IsBigEndianMacroBased())
|
||||
size = ReverseByteOrder(size);
|
||||
|
||||
packet[0] = static_cast<uint8_t>(type);
|
||||
|
|
Loading…
Add table
Reference in a new issue