Skip to content
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

8268873: Unnecessary Vector usage in java.base #4482

Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -284,11 +284,11 @@ public void write(OutputStream out) throws IOException {
public void read(InputStream is) throws IOException {
BufferedReader br = new BufferedReader
(new InputStreamReader(is, UTF_8.INSTANCE));
String line = null;
String line;
String currentJar = null;

/* an ordered list of jar file names */
Vector<String> jars = new Vector<>();
ArrayList<String> jars = new ArrayList<>();

/* read until we see a .jar line */
while((line = br.readLine()) != null && !line.endsWith(".jar"));
@@ -39,12 +39,10 @@
import java.net.Proxy;
import java.security.Principal;
import java.security.cert.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.StringTokenizer;
import java.util.Vector;

import javax.security.auth.x500.X500Principal;

import javax.net.ssl.*;
import sun.net.www.http.HttpClient;
@@ -148,14 +146,14 @@
ciphers = null;
} else {
StringTokenizer tokenizer;
Vector<String> v = new Vector<String>();
ArrayList<String> v = new ArrayList<>();

tokenizer = new StringTokenizer(cipherString, ",");
while (tokenizer.hasMoreTokens())
v.addElement(tokenizer.nextToken());
v.add(tokenizer.nextToken());
ciphers = new String [v.size()];
This conversation was marked as resolved by turbanoff

This comment has been minimized.

@stsypanov

stsypanov Jun 16, 2021
Contributor

Looks like this whole else block can be simplified to ciphers = cipherString.split(",");

This comment has been minimized.

@turbanoff

turbanoff Jun 16, 2021
Author Member

It's not a drop-in replacement. Result is different for some Strings. For example for , A
I would prefer to preserve existing behavior under this cleanup.

This comment has been minimized.

@stsypanov

stsypanov Jun 17, 2021
Contributor

Then let's keep it as is

for (int i = 0; i < ciphers.length; i++)
ciphers [i] = v.elementAt(i);
ciphers [i] = v.get(i);
}
return ciphers;
}
@@ -172,14 +170,14 @@
protocols = null;
} else {
StringTokenizer tokenizer;
Vector<String> v = new Vector<String>();
ArrayList<String> v = new ArrayList<>();

tokenizer = new StringTokenizer(protocolString, ",");
while (tokenizer.hasMoreTokens())
v.addElement(tokenizer.nextToken());
v.add(tokenizer.nextToken());
protocols = new String [v.size()];
for (int i = 0; i < protocols.length; i++) {
protocols [i] = v.elementAt(i);
protocols [i] = v.get(i);
}
}
return protocols;
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -578,19 +578,18 @@ public SignerInfo verify(SignerInfo info, byte[] bytes)
public SignerInfo[] verify(byte[] bytes)
throws NoSuchAlgorithmException, SignatureException {

Vector<SignerInfo> intResult = new Vector<>();
ArrayList<SignerInfo> intResult = new ArrayList<>();
for (int i = 0; i < signerInfos.length; i++) {

SignerInfo signerInfo = verify(signerInfos[i], bytes);
if (signerInfo != null) {
intResult.addElement(signerInfo);
intResult.add(signerInfo);
}
}
if (!intResult.isEmpty()) {

SignerInfo[] result = new SignerInfo[intResult.size()];
intResult.copyInto(result);
return result;
return intResult.toArray(result);
Comment on lines 591 to +592

This comment has been minimized.

@mbien

mbien Jun 15, 2021
Contributor

could be simplified to
return intResult.toArray(new SignerInfo[0]);
which would eliminate array zeroing as bonus as I have learned from your other PR ;)

This comment has been minimized.

@turbanoff

turbanoff Jun 16, 2021
Author Member

I considered this, when I was preparing the patch. But decided to reduce scope of changes.

}
return null;
}