!1704 Rectify coding specification problems

Merge pull request !1704 from zhaozhibo/master
This commit is contained in:
openharmony_ci 2022-07-05 10:07:20 +00:00 committed by Gitee
commit 4dcd076f3c
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 16 additions and 11 deletions

View File

@ -50,6 +50,7 @@ static constexpr char UTF8_FIRST_CODE[] = {
};
class StringHelper {
public:
static constexpr int INVALID_UNICODE_FROM_UTF8 = -1;
static std::string ToStdString(EcmaString *string);
static bool CheckDuplicate(EcmaString *string);
@ -202,12 +203,12 @@ public:
} else if (c == UICODE_FROM_UTF8[9] || c == UICODE_FROM_UTF8[10]) { // 9 - 10: 0400 0000 - 7FFF FFFF
l = 5; // 5: 0400 0000 - 7FFF FFFF Unicode
} else {
return -1;
return INVALID_UNICODE_FROM_UTF8;
}
/* check that we have enough characters */
if (l > (maxLen - 1))
return -1;
if (l > (maxLen - 1)) {
return INVALID_UNICODE_FROM_UTF8;
}
return FromUtf8(c, l, p, pp);
}
@ -218,12 +219,12 @@ public:
for (int i = 0; i < l; i++) {
b = *p++;
if (b < utf_helper::UTF8_2B_SECOND || b >= utf_helper::UTF8_2B_FIRST) {
return -1;
return INVALID_UNICODE_FROM_UTF8;
}
c = (c << 6) | (b & utf_helper::UTF8_2B_THIRD); // 6: Maximum Unicode range
}
if (c < UTF8_MIN_CODE[l - 1]) {
return -1;
return INVALID_UNICODE_FROM_UTF8;
}
*pp = p;
return c;

View File

@ -251,8 +251,15 @@ void Heap::Resume(TriggerGCType gcType)
}
if (activeSemiSpace_->AdjustCapacity(inactiveSemiSpace_->GetAllocatedSizeSinceGC())) {
// if activeSpace capacity changes oldSpace maximumCapacity should change, too.
size_t multiple = 2;
size_t oldSpaceMaxLimit = 0;
if (activeSemiSpace_->GetInitialCapacity() >= inactiveSemiSpace_->GetInitialCapacity()) {
size_t delta = activeSemiSpace_->GetInitialCapacity() - inactiveSemiSpace_->GetInitialCapacity();
size_t oldSpaceMaxLimit = oldSpace_->GetMaximumCapacity() - delta * 2;
oldSpaceMaxLimit = oldSpace_->GetMaximumCapacity() - delta * multiple;
} else {
size_t delta = inactiveSemiSpace_->GetInitialCapacity() - activeSemiSpace_->GetInitialCapacity();
oldSpaceMaxLimit = oldSpace_->GetMaximumCapacity() + delta * multiple;
}
oldSpace_->SetMaximumCapacity(oldSpaceMaxLimit);
inactiveSemiSpace_->SetInitialCapacity(activeSemiSpace_->GetInitialCapacity());
}

View File

@ -1146,7 +1146,6 @@ void SnapshotProcessor::DeserializeString(uintptr_t stringBegin, uintptr_t strin
size_t strSize = str->ObjectSize();
strSize = AlignUp(strSize, static_cast<size_t>(MemAlignment::MEM_ALIGN_OBJECT));
auto strFromTable = stringTable->GetString(str);
if (strFromTable) {
stringVector_.emplace_back(ToUintPtr(strFromTable));
} else {
@ -1455,7 +1454,6 @@ void *SnapshotProcessor::NativePointerEncodeBitToAddr(EncodeBit nativeBit)
size_t index = nativeBit.GetNativePointerOrObjectIndex();
void *addr = nullptr;
size_t nativeTableSize = GetNativeTableSize();
if (index < nativeTableSize - Constants::PROGRAM_NATIVE_METHOD_BEGIN) {
addr = reinterpret_cast<void *>(vm_->GetFactory()->nativeMethods_.at(index));
} else if (index < nativeTableSize) {
@ -1509,7 +1507,6 @@ void SnapshotProcessor::DeserializeNativePointer(uint64_t *value)
size_t index = native.GetNativePointerOrObjectIndex();
uintptr_t addr = 0U;
size_t nativeTableSize = GetNativeTableSize();
if (index < nativeTableSize - Constants::PROGRAM_NATIVE_METHOD_BEGIN) {
addr = reinterpret_cast<uintptr_t>(vm_->GetFactory()->nativeMethods_.at(index));
} else if (index < nativeTableSize) {