Skip to content

Speed improvements #157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ private String[] getJarToolArguments()
args.add( tempEmptyDir.getAbsolutePath() );
args.add( "." );

return args.toArray( new String[]{} );
return args.toArray( new String[0] );
}

}
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
46 changes: 33 additions & 13 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 @@ -61,23 +88,16 @@ public void clear()
*
* @param vPath The path to add.
*
* @return true if the path was not present, false if it already existed.
* @return true if the path was already present, false if it has been added.
*/
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 );
}

}