diff options
author | Marius Volkhart <mariusvolkhart@apache.org> | 2021-03-01 00:04:51 +0000 |
---|---|---|
committer | Marius Volkhart <mariusvolkhart@apache.org> | 2021-03-01 00:04:51 +0000 |
commit | 402d0fc5e56349b3d6f447d56c8eef77a91b73ff (patch) | |
tree | e7b5e97819f1ad689f341ffc112af38616249c8c /src/scratchpad/testcases/org | |
parent | d1c9a07860e365db4e335d24ad67e87544bdcceb (diff) | |
download | poi-402d0fc5e56349b3d6f447d56c8eef77a91b73ff.tar.gz poi-402d0fc5e56349b3d6f447d56c8eef77a91b73ff.zip |
Review EscherContainerRecord#getChildRecords() call sites for unnecessary work
This started off as wanting to add the EscherContainerRecord#getChildCount() function in order to do an efficient check for how many children the container has. This was desirable in new code for editing HSSF pictures. The existing option of calling getChildRecords().size() was undesirable as this requires a list copy first.
In the process of finding call sites that would benefit from replacing getChildRecords().size(), I realized that several other patterns would benefit from eliminating a copy, such as iterating over the children in a for-each loop, and indexed access to specific children.
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1887020 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/scratchpad/testcases/org')
-rw-r--r-- | src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBackground.java | 3 | ||||
-rw-r--r-- | src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPictures.java | 4 |
2 files changed, 3 insertions, 4 deletions
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBackground.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBackground.java index c105e08518..38bc03bb28 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBackground.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBackground.java @@ -211,8 +211,7 @@ public final class TestBackground { Document doc = ppt.getDocumentRecord(); EscherContainerRecord dggContainer = doc.getPPDrawingGroup().getDggContainer(); EscherContainerRecord bstore = HSLFShape.getEscherChild(dggContainer, EscherContainerRecord.BSTORE_CONTAINER); - List<EscherRecord> lst = bstore.getChildRecords(); - return ((EscherBSERecord)lst.get(idx-1)).getRef(); + return ((EscherBSERecord) bstore.getChild(idx - 1)).getRef(); } return 0; } diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPictures.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPictures.java index 40076c758f..a196ed685b 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPictures.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPictures.java @@ -712,7 +712,7 @@ public final class TestPictures { ByteArrayOutputStream inMemory = new ByteArrayOutputStream(); try (HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow("pictures.ppt")) { originalOffsets = ppt.getPictureData().stream().mapToInt(HSLFPictureData::getOffset).toArray(); - originalNumberOfRecords = ppt.getPictureData().get(0).bStore.getChildRecords().size(); + originalNumberOfRecords = ppt.getPictureData().get(0).bStore.getChildCount(); Random random = new Random(); for (HSLFPictureData picture : ppt.getPictureData()) { @@ -729,7 +729,7 @@ public final class TestPictures { assertArrayEquals(originalOffsets, offsets); // Verify that there are the same number of records as in the original slideshow. - int numberOfRecords = ppt.getPictureData().get(0).bStore.getChildRecords().size(); + int numberOfRecords = ppt.getPictureData().get(0).bStore.getChildCount(); assertEquals(originalNumberOfRecords, numberOfRecords); } } |