Stop using iterator in ArrayObject::sort (#8)

Signed-off-by: seonghyun kim <sh8281.kim@samsung.com>
This commit is contained in:
김승현/Web Platform Lab(S/W센터)/Engineer/삼성전자 2017-07-10 19:58:25 +09:00 committed by 최영일/Web Platform Lab(S/W센터)/Principal Engineer/삼성전자
commit 2d256f0140

View file

@ -190,14 +190,24 @@ void ArrayObject::sort(ExecutionState& state, std::function<bool(const Value& a,
{
if (isFastModeArray()) {
if (getArrayLength(state)) {
std::vector<Value, GCUtil::gc_malloc_ignore_off_page_allocator<Value>> values(&m_fastModeData[0], m_fastModeData.data() + getArrayLength(state));
std::sort(values.begin(), values.end(), comp);
if (getArrayLength(state) != values.size()) {
setArrayLength(state, values.size());
size_t orgLength = getArrayLength(state);
Value* tempBuffer = (Value*)GC_MALLOC_IGNORE_OFF_PAGE(sizeof(Value) * orgLength);
for (size_t i = 0; i < orgLength; i++) {
tempBuffer[i] = m_fastModeData[i];
}
for (size_t i = 0; i < values.size(); i++) {
m_fastModeData[i] = values[i];
std::sort(tempBuffer, tempBuffer + orgLength, comp);
if (getArrayLength(state) != orgLength) {
setArrayLength(state, orgLength);
}
if (isFastModeArray()) {
for (size_t i = 0; i < orgLength; i++) {
m_fastModeData[i] = tempBuffer[i];
}
}
GC_FREE(tempBuffer);
}
return;
}