Skip to content

Commit 8a08574

Browse files
gnodetplamentotev
authored andcommitted
Use non synchronized collections
1 parent 3ef935a commit 8a08574

File tree

2 files changed

+34
-14
lines changed

2 files changed

+34
-14
lines changed

src/main/java/org/codehaus/plexus/archiver/zip/AbstractZipArchiver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
import java.nio.charset.Charset;
2727
import java.util.Calendar;
2828
import java.util.Date;
29+
import java.util.Deque;
2930
import java.util.Hashtable;
30-
import java.util.Stack;
3131
import java.util.concurrent.ExecutionException;
3232
import java.util.zip.CRC32;
3333
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
@@ -408,7 +408,7 @@ private void addParentDirs( ArchiveEntry archiveEntry, File baseDir, String entr
408408
{
409409
if ( !doFilesonly && getIncludeEmptyDirs() )
410410
{
411-
Stack<String> directories = addedDirs.asStringStack( entry );
411+
Deque<String> directories = addedDirs.asStringDeque( entry );
412412

413413
while ( !directories.isEmpty() )
414414
{

src/main/java/org/codehaus/plexus/archiver/zip/AddedDirs.java

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
*/
1717
package org.codehaus.plexus.archiver.zip;
1818

19+
import java.util.ArrayDeque;
20+
import java.util.Deque;
1921
import java.util.HashSet;
20-
import java.util.Hashtable;
2122
import java.util.Set;
2223
import java.util.Stack;
2324

@@ -27,11 +28,37 @@
2728
public class AddedDirs
2829
{
2930

30-
private final Hashtable<String, String> addedDirs = new Hashtable<String, String>();
31+
private final Set<String> addedDirs = new HashSet<String>();
3132

33+
/**
34+
* @deprecated use {@link #asStringDeque(String)} instead.
35+
*/
36+
@Deprecated
3237
public Stack<String> asStringStack( String entry )
3338
{
34-
Stack<String> directories = new Stack<String>();
39+
Stack<String> directories = new Stack<>();
40+
41+
// Don't include the last entry itself if it's
42+
// a dir; it will be added on its own.
43+
int slashPos = entry.length() - ( entry.endsWith( "/" ) ? 1 : 0 );
44+
45+
while ( ( slashPos = entry.lastIndexOf( '/', slashPos - 1 ) ) != -1 )
46+
{
47+
String dir = entry.substring( 0, slashPos + 1 );
48+
49+
if ( addedDirs.contains( dir ) )
50+
{
51+
break;
52+
}
53+
54+
directories.push( dir );
55+
}
56+
return directories;
57+
}
58+
59+
public Deque<String> asStringDeque( String entry )
60+
{
61+
Deque<String> directories = new ArrayDeque<>();
3562

3663
// Don't include the last entry itself if it's
3764
// a dir; it will be added on its own.
@@ -65,19 +92,12 @@ public void clear()
6592
*/
6693
public boolean update( String vPath )
6794
{
68-
if ( addedDirs.get( vPath ) != null )
69-
{
70-
// don't add directories we've already added.
71-
// no warning if we try, it is harmless in and of itself
72-
return true;
73-
}
74-
addedDirs.put( vPath, vPath );
75-
return false;
95+
return !addedDirs.add( vPath );
7696
}
7797

7898
public Set<String> allAddedDirs()
7999
{
80-
return new HashSet<String>( addedDirs.keySet() );
100+
return new HashSet<String>( addedDirs );
81101
}
82102

83103
}

0 commit comments

Comments
 (0)