git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[JGIT PATCH 4/4] Use a singleton for the NullProgressMonitor implementation

From
Shawn O. Pearce <spearce@spearce.org>
Date
Jul 9, 2008, 04:15 UTC
Message-ID
<1215576931-4174-5-git-send-email-spearce@spearce.org>
In-Reply-To
<1215576931-4174-4-git-send-email-spearce@spearce.org>

No reason to create a new instance every time we need to shove a null monitor into a variable because someone passed us null.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 .../org/spearce/jgit/lib/NullProgressMonitor.java  |    3 +++
 .../src/org/spearce/jgit/util/TemporaryBuffer.java |    2 +-
 2 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/NullProgressMonitor.java b/org.spearce.jgit/src/org/spearce/jgit/lib/NullProgressMonitor.java
index de75b90..191dc00 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/NullProgressMonitor.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/NullProgressMonitor.java
@@ -42,6 +42,9 @@ package org.spearce.jgit.lib;
  * A NullProgressMonitor does not report progress anywhere.
  */
 public class NullProgressMonitor implements ProgressMonitor {
+	/** Immutable instance of a null progress monitor. */
+	public static final NullProgressMonitor INSTANCE = new NullProgressMonitor();
+
 	public void start(int totalTasks) {
 		// Do not report.
 	}
diff --git a/org.spearce.jgit/src/org/spearce/jgit/util/TemporaryBuffer.java b/org.spearce.jgit/src/org/spearce/jgit/util/TemporaryBuffer.java
index 20db580..d597c38 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/util/TemporaryBuffer.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/util/TemporaryBuffer.java
@@ -200,7 +200,7 @@ public class TemporaryBuffer extends OutputStream {
 	public void writeTo(final OutputStream os, ProgressMonitor pm)
 			throws IOException {
 		if (pm == null)
-			pm = new NullProgressMonitor();
+			pm = NullProgressMonitor.INSTANCE;
 		if (blocks != null) {
 			// Everything is in core so we can stream directly to the output.
 			//
-- 
1.5.6.74.g8a5e
Previous: Shawn O. Pearce
Message 5 of 5 in “Misc. push transport fixes”
  1. 0/4 Misc. push transport fixesShawn O. Pearce, Jul 9, 2008
  2. 1/4 Avoid deadlock while fetching from local repositoryShawn O. Pearce, Jul 9, 2008
  3. 2/4 Fix pushing of annotated tags to actually include the tag objectShawn O. Pearce, Jul 9, 2008
  4. 3/4 Automatically initialize a new dumb repository during pushShawn O. Pearce, Jul 9, 2008
  5. 4/4 Use a singleton for the NullProgressMonitor implementationShawn O. Pearce, Jul 9, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.