Merge branch 'master' into clang-tidy-perf-fixes

pull/3964/head
Kim Kulling 2021-06-29 20:24:23 +02:00 committed by GitHub
commit 59ab791a47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 28 additions and 23 deletions

View File

@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
Copyright (c) 2006-2021, assimp team Copyright (c) 2006-2021, assimp team
All rights reserved. All rights reserved.
Redistribution and use of this software in source and binary forms, Redistribution and use of this software in source and binary forms,
@ -777,12 +776,13 @@ inline void Buffer::EncodedRegion_Mark(const size_t pOffset, const size_t pEncod
} }
inline void Buffer::EncodedRegion_SetCurrent(const std::string &pID) { inline void Buffer::EncodedRegion_SetCurrent(const std::string &pID) {
if ((EncodedRegion_Current != nullptr) && (EncodedRegion_Current->ID == pID)) return; if ((EncodedRegion_Current != nullptr) && (EncodedRegion_Current->ID == pID)) {
return;
}
for (SEncodedRegion *reg : EncodedRegion_List) { for (SEncodedRegion *reg : EncodedRegion_List) {
if (reg->ID == pID) { if (reg->ID == pID) {
EncodedRegion_Current = reg; EncodedRegion_Current = reg;
return; return;
} }
} }
@ -832,10 +832,13 @@ inline bool Buffer::ReplaceData_joint(const size_t pBufferData_Offset, const siz
} }
inline size_t Buffer::AppendData(uint8_t *data, size_t length) { inline size_t Buffer::AppendData(uint8_t *data, size_t length) {
size_t offset = this->byteLength; const size_t offset = this->byteLength;
// Force alignment to 4 bits // Force alignment to 4 bits
Grow((length + 3) & ~3); const size_t paddedLength = (length + 3) & ~3;
Grow(paddedLength);
memcpy(mData.get() + offset, data, length); memcpy(mData.get() + offset, data, length);
memset(mData.get() + offset + length, 0, paddedLength - length);
return offset; return offset;
} }
@ -864,9 +867,7 @@ inline void Buffer::Grow(size_t amount) {
// //
// struct BufferView // struct BufferView
// //
inline void BufferView::Read(Value &obj, Asset &r) { inline void BufferView::Read(Value &obj, Asset &r) {
if (Value *bufferVal = FindUInt(obj, "buffer")) { if (Value *bufferVal = FindUInt(obj, "buffer")) {
buffer = r.buffers.Retrieve(bufferVal->GetUint()); buffer = r.buffers.Retrieve(bufferVal->GetUint());
} }
@ -886,17 +887,22 @@ inline void BufferView::Read(Value &obj, Asset &r) {
} }
inline uint8_t *BufferView::GetPointer(size_t accOffset) { inline uint8_t *BufferView::GetPointer(size_t accOffset) {
if (!buffer) return nullptr; if (!buffer) {
return nullptr;
}
uint8_t *basePtr = buffer->GetPointer(); uint8_t *basePtr = buffer->GetPointer();
if (!basePtr) return nullptr; if (!basePtr) {
return nullptr;
}
size_t offset = accOffset + byteOffset; size_t offset = accOffset + byteOffset;
if (buffer->EncodedRegion_Current != nullptr) { if (buffer->EncodedRegion_Current != nullptr) {
const size_t begin = buffer->EncodedRegion_Current->Offset; const size_t begin = buffer->EncodedRegion_Current->Offset;
const size_t end = begin + buffer->EncodedRegion_Current->DecodedData_Length; const size_t end = begin + buffer->EncodedRegion_Current->DecodedData_Length;
if ((offset >= begin) && (offset < end)) if ((offset >= begin) && (offset < end)) {
return &buffer->EncodedRegion_Current->DecodedData[offset - begin]; return &buffer->EncodedRegion_Current->DecodedData[offset - begin];
} }
}
return basePtr + offset; return basePtr + offset;
} }
@ -944,7 +950,6 @@ inline void Accessor::Sparse::PatchData(unsigned int elementSize) {
} }
inline void Accessor::Read(Value &obj, Asset &r) { inline void Accessor::Read(Value &obj, Asset &r) {
if (Value *bufferViewVal = FindUInt(obj, "bufferView")) { if (Value *bufferViewVal = FindUInt(obj, "bufferView")) {
bufferView = r.bufferViews.Retrieve(bufferViewVal->GetUint()); bufferView = r.bufferViews.Retrieve(bufferViewVal->GetUint());
} }