Skip to content

Commit 8304265

Browse files
jsikstropull[bot]
authored andcommitted
8342102: ZGC: Optimize copy constructors in ZPhysicalMemory
Reviewed-by: stefank, kbarrett, aboldtch
1 parent 1c0c36c commit 8304265

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/hotspot/share/gc/z/zPhysicalMemory.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -46,20 +46,24 @@ ZPhysicalMemory::ZPhysicalMemory()
4646

4747
ZPhysicalMemory::ZPhysicalMemory(const ZPhysicalMemorySegment& segment)
4848
: _segments() {
49-
add_segment(segment);
49+
_segments.append(segment);
5050
}
5151

5252
ZPhysicalMemory::ZPhysicalMemory(const ZPhysicalMemory& pmem)
53-
: _segments() {
54-
add_segments(pmem);
53+
: _segments(pmem.nsegments()) {
54+
_segments.appendAll(&pmem._segments);
5555
}
5656

5757
const ZPhysicalMemory& ZPhysicalMemory::operator=(const ZPhysicalMemory& pmem) {
58-
// Free segments
59-
_segments.clear_and_deallocate();
58+
// Check for self-assignment
59+
if (this == &pmem) {
60+
return *this;
61+
}
6062

61-
// Copy segments
62-
add_segments(pmem);
63+
// Free and copy segments
64+
_segments.clear_and_deallocate();
65+
_segments.reserve(pmem.nsegments());
66+
_segments.appendAll(&pmem._segments);
6367

6468
return *this;
6569
}

0 commit comments

Comments
 (0)