Skip to content

Commit

Permalink
Use non synchronized collections
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet authored and plamentotev committed Mar 22, 2021
1 parent 3ef935a commit 8a08574
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import java.nio.charset.Charset;
import java.util.Calendar;
import java.util.Date;
import java.util.Deque;
import java.util.Hashtable;
import java.util.Stack;
import java.util.concurrent.ExecutionException;
import java.util.zip.CRC32;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
Expand Down Expand Up @@ -408,7 +408,7 @@ private void addParentDirs( ArchiveEntry archiveEntry, File baseDir, String entr
{
if ( !doFilesonly && getIncludeEmptyDirs() )
{
Stack<String> directories = addedDirs.asStringStack( entry );
Deque<String> directories = addedDirs.asStringDeque( entry );

while ( !directories.isEmpty() )
{
Expand Down
44 changes: 32 additions & 12 deletions src/main/java/org/codehaus/plexus/archiver/zip/AddedDirs.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
*/
package org.codehaus.plexus.archiver.zip;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Set;
import java.util.Stack;

Expand All @@ -27,11 +28,37 @@
public class AddedDirs
{

private final Hashtable<String, String> addedDirs = new Hashtable<String, String>();
private final Set<String> addedDirs = new HashSet<String>();

/**
* @deprecated use {@link #asStringDeque(String)} instead.
*/
@Deprecated
public Stack<String> asStringStack( String entry )
{
Stack<String> directories = new Stack<String>();
Stack<String> directories = new Stack<>();

// Don't include the last entry itself if it's
// a dir; it will be added on its own.
int slashPos = entry.length() - ( entry.endsWith( "/" ) ? 1 : 0 );

while ( ( slashPos = entry.lastIndexOf( '/', slashPos - 1 ) ) != -1 )
{
String dir = entry.substring( 0, slashPos + 1 );

if ( addedDirs.contains( dir ) )
{
break;
}

directories.push( dir );
}
return directories;
}

public Deque<String> asStringDeque( String entry )
{
Deque<String> directories = new ArrayDeque<>();

// Don't include the last entry itself if it's
// a dir; it will be added on its own.
Expand Down Expand Up @@ -65,19 +92,12 @@ public void clear()
*/
public boolean update( String vPath )
{
if ( addedDirs.get( vPath ) != null )
{
// don't add directories we've already added.
// no warning if we try, it is harmless in and of itself
return true;
}
addedDirs.put( vPath, vPath );
return false;
return !addedDirs.add( vPath );
}

public Set<String> allAddedDirs()
{
return new HashSet<String>( addedDirs.keySet() );
return new HashSet<String>( addedDirs );
}

}

0 comments on commit 8a08574

Please sign in to comment.