Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #30 from jglick/intern
[FIXED JENKINS-19458] Intern CvsFile instances
  • Loading branch information
mc1arke committed May 2, 2014
2 parents 8ba48c2 + 293f360 commit 68bfea2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/main/java/hudson/scm/AbstractCvs.java
Expand Up @@ -908,15 +908,15 @@ public List<CvsFile> buildFileList(final File moduleLocation, final String prefi
if (moduleLocation.isFile()) {
Entry entry = adminHandler.getEntry(moduleLocation);
if (entry != null) {
fileList.add(new CvsFile(entry.getName(), entry.getRevision()));
fileList.add(CvsFile.make(entry.getName(), entry.getRevision()));
}
} else {
for (File file : adminHandler.getAllFiles(moduleLocation)) {


if (file.isFile()) {
Entry entry = adminHandler.getEntry(file);
CvsFile currentFile = new CvsFile(prefix + "/" + entry.getName(), entry.getRevision());
CvsFile currentFile = CvsFile.make(prefix + "/" + entry.getName(), entry.getRevision());
fileList.add(currentFile);
}
}
Expand Down
23 changes: 19 additions & 4 deletions src/main/java/hudson/scm/CvsFile.java
Expand Up @@ -23,6 +23,8 @@
*/
package hudson.scm;

import com.google.common.collect.Interner;
import com.google.common.collect.Interners;
import java.io.Serializable;

import org.kohsuke.stapler.export.Exported;
Expand All @@ -31,21 +33,34 @@ public class CvsFile implements Serializable {

private static final long serialVersionUID = -3429721308650490782L;

private static final Interner<CvsFile> INTERNER = Interners.newWeakInterner();

private final String name;
private final String revision;
private final boolean dead;

public CvsFile(final String name, final String revision) {
this(name, revision, false);
public static CvsFile make(final String name, final String revision) {
return make(name, revision, false);
}

public static CvsFile make(final String name, final String revision,
final boolean isDead) {
return INTERNER.intern(new CvsFile(name, revision, isDead));
}

public CvsFile(final String name, final String revision,
private CvsFile(final String name, final String revision,
final boolean isDead) {
// Could intern name in a separate INTERNER, though most files will probably not have been modified recently anyway.
this.name = name;
this.revision = revision;
this.revision = revision.intern();
dead = isDead;
}

private Object readResolve() {
// Could make(name, revision, dead) to reintern revision, but probably pointless since com.thoughtworks.xstream.converters.basic.StringConverter caches instances.
return INTERNER.intern(this);
}

@Exported
public String getName() {
return name;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/hudson/scm/CvsLog.java
Expand Up @@ -423,7 +423,7 @@ private void saveChange(final CVSChangeLogSet.File file, final CVSChangeLog chan
// we only want the first listing of this file since changes are
// sorted in reverse order of when they were made
if (!files.containsKey(file.getFullName())) {
final CvsFile cvsFile = new CvsFile(file.getFullName(), file.getRevision(), file.isDead());
final CvsFile cvsFile = CvsFile.make(file.getFullName(), file.getRevision(), file.isDead());
files.put(file.getFullName(), cvsFile);
}

Expand Down
6 changes: 3 additions & 3 deletions src/test/java/hudson/scm/CVSSCMTest.java
Expand Up @@ -170,9 +170,9 @@ public void testFlattenEnabled() {
@Test
public void testExcludeRegions() throws IOException, InterruptedException {
List<CvsFile> files = new ArrayList<CvsFile>();
files.add(new CvsFile("test.ext", "1.1", false));
files.add(new CvsFile("subdir/test.ext", "1.1", false));
files.add(new CvsFile("subdir/subdir2/test.ext", "1.1", false));
files.add(CvsFile.make("test.ext", "1.1", false));
files.add(CvsFile.make("subdir/test.ext", "1.1", false));
files.add(CvsFile.make("subdir/subdir2/test.ext", "1.1", false));
CustomFreeStyleProject project = new CustomFreeStyleProject(jenkinsRule.getInstance(), "testProject");
project.getLastBuild().setChangeSetComputed(true);
CvsRepository repository = new CvsRepository("repo", false, null, Arrays.<CvsRepositoryItem>asList(),
Expand Down

0 comments on commit 68bfea2

Please sign in to comment.