You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by dk...@apache.org on 2020/05/21 15:45:29 UTC
[avro] branch master updated: Initialize the buffer area for
Stringbuilder/List
This is an automated email from the ASF dual-hosted git repository.
dkulp pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/avro.git
The following commit(s) were added to refs/heads/master by this push:
new dab5fbe Initialize the buffer area for Stringbuilder/List
dab5fbe is described below
commit dab5fbe35e7bafcf86eb587cf4c6a898ea57f673
Author: zeshuai007 <51...@qq.com>
AuthorDate: Tue Mar 31 16:33:24 2020 +0800
Initialize the buffer area for Stringbuilder/List
---
.../avro/compiler/specific/SpecificCompiler.java | 11 +++++-----
.../org/apache/avro/mojo/AbstractAvroMojo.java | 13 ++++++------
.../org/apache/avro/protobuf/ProtobufData.java | 6 +++---
.../src/main/java/org/apache/avro/tool/Util.java | 24 +++++++++++-----------
4 files changed, 28 insertions(+), 26 deletions(-)
diff --git a/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java b/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java
index 2f2b942..317098f 100644
--- a/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java
+++ b/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java
@@ -485,7 +485,7 @@ public class SpecificCompiler {
/** Generate java classes for enqueued schemas. */
Collection<OutputFile> compile() {
- List<OutputFile> out = new ArrayList<>();
+ List<OutputFile> out = new ArrayList<>(queue.size() + 1);
for (Schema schema : queue) {
out.add(compile(schema));
}
@@ -667,7 +667,7 @@ public class SpecificCompiler {
for (String alias : s.getAliases())
result.addAlias(alias, null); // copy aliases
seen.put(s, result);
- List<Field> newFields = new ArrayList<>();
+ List<Field> newFields = new ArrayList<>(s.getFields().size());
for (Field f : s.getFields()) {
Schema fSchema = addStringType(f.schema(), seen);
Field newF = new Field(f, fSchema);
@@ -685,7 +685,7 @@ public class SpecificCompiler {
GenericData.setStringType(result, stringType);
break;
case UNION:
- List<Schema> types = new ArrayList<>();
+ List<Schema> types = new ArrayList<>(s.getTypes().size());
for (Schema branch : s.getTypes())
types.add(addStringType(branch, seen));
result = Schema.createUnion(types);
@@ -954,7 +954,7 @@ public class SpecificCompiler {
return new String[] { value.toString() };
if (value instanceof List) {
final List<?> list = (List<?>) value;
- final List<String> annots = new ArrayList<>();
+ final List<String> annots = new ArrayList<>(list.size());
for (Object o : list) {
annots.add(o.toString());
}
@@ -974,7 +974,8 @@ public class SpecificCompiler {
* @return A sequence of quoted, comma-separated, escaped strings
*/
public String javaSplit(String s) throws IOException {
- StringBuilder b = new StringBuilder("\""); // initial quote
+ StringBuilder b = new StringBuilder(s.length());
+ b.append("\""); // initial quote
for (int i = 0; i < s.length(); i += maxStringChars) {
if (i != 0)
b.append("\",\""); // insert quote-comma-quote
diff --git a/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/AbstractAvroMojo.java b/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/AbstractAvroMojo.java
index 599b096..cbac38c 100644
--- a/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/AbstractAvroMojo.java
+++ b/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/AbstractAvroMojo.java
@@ -302,12 +302,13 @@ public abstract class AbstractAvroMojo extends AbstractMojo {
}
private List<URL> appendElements(List runtimeClasspathElements) throws MalformedURLException {
- List<URL> runtimeUrls = new ArrayList<>();
- if (runtimeClasspathElements != null) {
- for (Object runtimeClasspathElement : runtimeClasspathElements) {
- String element = (String) runtimeClasspathElement;
- runtimeUrls.add(new File(element).toURI().toURL());
- }
+ if (runtimeClasspathElements == null) {
+ return new ArrayList<>();
+ }
+ List<URL> runtimeUrls = new ArrayList<>(runtimeClasspathElements.size());
+ for (Object runtimeClasspathElement : runtimeClasspathElements) {
+ String element = (String) runtimeClasspathElement;
+ runtimeUrls.add(new File(element).toURI().toURL());
}
return runtimeUrls;
}
diff --git a/lang/java/protobuf/src/main/java/org/apache/avro/protobuf/ProtobufData.java b/lang/java/protobuf/src/main/java/org/apache/avro/protobuf/ProtobufData.java
index 9b5737a..c4c0d9c 100644
--- a/lang/java/protobuf/src/main/java/org/apache/avro/protobuf/ProtobufData.java
+++ b/lang/java/protobuf/src/main/java/org/apache/avro/protobuf/ProtobufData.java
@@ -212,7 +212,7 @@ public class ProtobufData extends GenericData {
seen.put(descriptor, result);
- List<Field> fields = new ArrayList<>();
+ List<Field> fields = new ArrayList<>(descriptor.getFields().size());
for (FieldDescriptor f : descriptor.getFields())
fields.add(Accessor.createField(f.getName(), getSchema(f), null, getDefault(f)));
result.setFields(fields);
@@ -253,7 +253,7 @@ public class ProtobufData extends GenericData {
private static String toCamelCase(String s) {
String[] parts = s.split("_");
- StringBuilder camelCaseString = new StringBuilder();
+ StringBuilder camelCaseString = new StringBuilder(s.length());
for (String part : parts) {
camelCaseString.append(cap(part));
}
@@ -315,7 +315,7 @@ public class ProtobufData extends GenericData {
}
public Schema getSchema(EnumDescriptor d) {
- List<String> symbols = new ArrayList<>();
+ List<String> symbols = new ArrayList<>(d.getValues().size());
for (EnumValueDescriptor e : d.getValues()) {
symbols.add(e.getName());
}
diff --git a/lang/java/tools/src/main/java/org/apache/avro/tool/Util.java b/lang/java/tools/src/main/java/org/apache/avro/tool/Util.java
index f3d2d60..add633e 100644
--- a/lang/java/tools/src/main/java/org/apache/avro/tool/Util.java
+++ b/lang/java/tools/src/main/java/org/apache/avro/tool/Util.java
@@ -56,7 +56,7 @@ class Util {
* Returns stdin if filename is "-", else opens the File in the owning
* filesystem and returns an InputStream for it. Relative paths will be opened
* in the default filesystem.
- *
+ *
* @param filename The filename to be opened
* @throws IOException
*/
@@ -68,7 +68,7 @@ class Util {
* Returns stdout if filename is "-", else opens the file from the owning
* filesystem and returns an OutputStream for it. Relative paths will be opened
* in the default filesystem.
- *
+ *
* @param filename The filename to be opened
* @throws IOException
*/
@@ -79,7 +79,7 @@ class Util {
/**
* Returns an InputStream for the file using the owning filesystem, or the
* default if none is given.
- *
+ *
* @param filename The filename to be opened
* @throws IOException
*/
@@ -91,7 +91,7 @@ class Util {
/**
* Returns an InputStream for the file using the owning filesystem, or the
* default if none is given.
- *
+ *
* @param filename The filename to be opened
* @throws IOException
*/
@@ -102,7 +102,7 @@ class Util {
/**
* Returns a seekable FsInput using the owning filesystem, or the default if
* none is given.
- *
+ *
* @param filename The filename to be opened
* @throws IOException
*/
@@ -113,7 +113,7 @@ class Util {
/**
* Opens the file for writing in the owning filesystem, or the default if none
* is given.
- *
+ *
* @param filename The filename to be opened.
* @return An OutputStream to the specified file.
* @throws IOException
@@ -126,7 +126,7 @@ class Util {
/**
* Closes the inputstream created from {@link Util.fileOrStdin} unless it is
* System.in.
- *
+ *
* @param in The inputstream to be closed.
*/
static void close(InputStream in) {
@@ -142,7 +142,7 @@ class Util {
/**
* Closes the outputstream created from {@link Util.fileOrStdout} unless it is
* System.out.
- *
+ *
* @param out The outputStream to be closed.
*/
static void close(OutputStream out) {
@@ -157,7 +157,7 @@ class Util {
/**
* Parses a schema from the specified file.
- *
+ *
* @param filename The file name to parse
* @return The parsed schema
* @throws IOException
@@ -180,7 +180,7 @@ class Util {
* included.
*
* The List is sorted alphabetically.
- *
+ *
* @param fileOrDirName filename, directoryname or a glob pattern
* @return A Path List
* @throws IOException
@@ -218,13 +218,13 @@ class Util {
* subdirectories or files within those.
*
* The list is sorted alphabetically.
- *
+ *
* @param fileOrDirNames A list of filenames, directorynames or glob patterns
* @return A list of Paths, one for each file
* @throws IOException
*/
static List<Path> getFiles(List<String> fileOrDirNames) throws IOException {
- ArrayList<Path> pathList = new ArrayList<>();
+ ArrayList<Path> pathList = new ArrayList<>(fileOrDirNames.size());
for (String name : fileOrDirNames) {
pathList.addAll(getFiles(name));
}