Stephen McKamey avatar Stephen McKamey committed 84a9b21

reusing buffer for less wasteful memory

Comments (0)

Files changed (1)

merge-builder/src/main/java/org/duelengine/merge/NullCompactor.java

 
 	private static final int BUFFER_SIZE = 4096;
 	private final String[] extensions;
+	private byte[] buffer;
 
 	public NullCompactor(String... extensions) {
 		this.extensions = (extensions != null) ? extensions : new String[0];
 	public void calcHash(BuildManager manager, MessageDigest hash, String path, File source)
 			throws IOException, NoSuchAlgorithmException {
 
+		if (buffer == null) {
+			buffer = new byte[BUFFER_SIZE];
+		}
+
 		FileInputStream stream = new FileInputStream(source);
 		try {
-			final byte[] buffer = new byte[BUFFER_SIZE];
-
 			int count;
 			while ((count = stream.read(buffer)) > 0) {
 				hash.update(buffer, 0, count);
 	public void compact(BuildManager manager, String path, File source, File target)
 			throws IOException {
 
+		if (buffer == null) {
+			buffer = new byte[BUFFER_SIZE];
+		}
+
 		// ensure parent path exists
 		target.getParentFile().mkdirs();
 
 		FileInputStream inStream = new FileInputStream(source);
 		FileOutputStream outStream = new FileOutputStream(target);
 		try {
-			final byte[] buffer = new byte[BUFFER_SIZE];
-
 			int count;
 			while ((count = inStream.read(buffer)) > 0) {
 				outStream.write(buffer, 0, count);
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.