MCPcopy Create free account
hub / github.com/ShiftLeftSecurity/overflowdb / trim

Method trim

core/src/main/java/overflowdb/NodeDb.java:755–779  ·  view source on GitHub ↗

Trims the node to save storage: shrinks overallocations

()

Source from the content-addressed store, hash-verified

753 * Trims the node to save storage: shrinks overallocations
754 * */
755 public synchronized long trim() {
756 AdjacentNodes adjacentNodesOld = this.adjacentNodes;
757 int newSize = 0;
758 int until = adjacentNodesOld.offsetLengths();
759 for (int offsetPos = 0; 2 * offsetPos < until; offsetPos++) {
760 int length = blockLength(adjacentNodesOld, offsetPos);
761 newSize += length;
762 }
763 Object[] nodesWithEdgePropertiesNew = new Object[newSize];
764 AdjacentNodes res = new AdjacentNodes(nodesWithEdgePropertiesNew, new byte[until]);
765
766 int off = 0;
767 for(int offsetPos = 0; 2*offsetPos < until; offsetPos++){
768 int start = startIndex(adjacentNodesOld, offsetPos);
769 int length = blockLength(adjacentNodesOld, offsetPos);
770 System.arraycopy(adjacentNodesOld.nodesWithEdgeProperties, start, nodesWithEdgePropertiesNew, off, length);
771 res = res.setOffset(2 * offsetPos, off);
772 res = res.setOffset(2 * offsetPos + 1, length);
773 off += length;
774 }
775 int oldSize = adjacentNodesOld.nodesWithEdgeProperties.length;
776 this.adjacentNodes = res;
777
778 return (long) newSize + (((long) oldSize) << 32);
779 }
780
781 public final boolean isDirty() {
782 return dirty;

Callers 1

overviewTestMethod · 0.80

Calls 4

offsetLengthsMethod · 0.95
blockLengthMethod · 0.95
startIndexMethod · 0.95
setOffsetMethod · 0.95

Tested by 1

overviewTestMethod · 0.64