Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Avoid unnecessary work for identical locations in Buffer.BlockCopy #36

Merged
merged 1 commit into from
Feb 4, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/vm/comutilnative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1443,9 +1443,12 @@ FCIMPL5(VOID, Buffer::BlockCopy, ArrayBase *src, int srcOffset, ArrayBase *dst,
if (srcLen < (SIZE_T)srcOffset + (SIZE_T)count || dstLen < (SIZE_T)dstOffset + (SIZE_T)count) {
FCThrowArgumentVoid(NULL, W("Argument_InvalidOffLen"));
}

PTR_BYTE srcPtr = src->GetDataPtr() + srcOffset;
PTR_BYTE dstPtr = dst->GetDataPtr() + dstOffset;

if (count > 0) {
memmove(dst->GetDataPtr() + dstOffset, src->GetDataPtr() + srcOffset, count);
if ((srcPtr != dstPtr) && (count > 0)) {
memmove(dstPtr, srcPtr, count);
}

FC_GC_POLL();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should FC_GC_POLL() also be moved inside the if test, i.e. only run when work is done?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FC_GC_POLL should be done all the time even when no work is done. Otherwise, there is a risk of GC starvation - the suspension for GC would take hang if there is a thread that calls BlockCopy in a tight loop.

Expand Down