-
Notifications
You must be signed in to change notification settings - Fork 123
#1888 use StringBuilderWriter instead of StringWriter in performance hotspot to reduce locking #1889
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
Open
winfriedgerlach
wants to merge
3
commits into
eclipse-ee4j:master
Choose a base branch
from
winfriedgerlach:#1888-use-StringBuilder-Writer
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+175
−6
Open
#1888 use StringBuilderWriter instead of StringWriter in performance hotspot to reduce locking #1889
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
170 changes: 170 additions & 0 deletions
170
.../impl/src/main/java/org/glassfish/jaxb/runtime/v2/runtime/output/StringBuilderWriter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,170 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| //@@3RD PARTY CODE@@ | ||
|
|
||
| package org.glassfish.jaxb.runtime.v2.runtime.output; | ||
|
|
||
| import java.io.Serializable; | ||
| import java.io.Writer; | ||
|
|
||
| /** | ||
| * <p> | ||
| * Copied from | ||
| * <a href="https://github.com/apache/commons-io/blob/master/src/main/java/org/apache/commons/io/output/StringBuilderWriter.java">Apache commons-io</a>. | ||
| * <p> | ||
| * {@link Writer} implementation that outputs to a {@link StringBuilder}. | ||
| * <p> | ||
| * <strong>NOTE:</strong> This implementation, as an alternative to {@link java.io.StringWriter}, provides an | ||
| * <em>un-synchronized</em> implementation for better performance for use in a single thread. For safe usage with | ||
| * multiple {@link Thread}s, a {@link java.io.StringWriter} should be used. | ||
| */ | ||
| public class StringBuilderWriter extends Writer implements Serializable { | ||
|
|
||
| private static final long serialVersionUID = -146927496096066153L; | ||
|
|
||
| /** The append target. */ | ||
| private final StringBuilder builder; | ||
|
|
||
| /** | ||
| * Constructs a new {@link StringBuilder} instance with default capacity. | ||
| */ | ||
| public StringBuilderWriter() { | ||
| this.builder = new StringBuilder(); | ||
| } | ||
|
|
||
| /** | ||
| * Constructs a new {@link StringBuilder} instance with the specified capacity. | ||
| * | ||
| * @param capacity The initial capacity of the underlying {@link StringBuilder} | ||
| */ | ||
| public StringBuilderWriter(final int capacity) { | ||
| this.builder = new StringBuilder(capacity); | ||
| } | ||
|
|
||
| /** | ||
| * Constructs a new instance with the specified {@link StringBuilder}. | ||
| * | ||
| * <p>If {@code builder} is null a new instance with default capacity will be created.</p> | ||
| * | ||
| * @param builder The String builder. May be null. | ||
| */ | ||
| public StringBuilderWriter(final StringBuilder builder) { | ||
| this.builder = builder != null ? builder : new StringBuilder(); | ||
| } | ||
|
|
||
| /** | ||
| * Appends a single character to this Writer. | ||
| * | ||
| * @param value The character to append | ||
| * @return This writer instance | ||
| */ | ||
| @Override | ||
| public Writer append(final char value) { | ||
| builder.append(value); | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Appends a character sequence to this Writer. | ||
| * | ||
| * @param value The character to append | ||
| * @return This writer instance | ||
| */ | ||
| @Override | ||
| public Writer append(final CharSequence value) { | ||
| builder.append(value); | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Appends a portion of a character sequence to the {@link StringBuilder}. | ||
| * | ||
| * @param value The character to append | ||
| * @param start The index of the first character | ||
| * @param end The index of the last character + 1 | ||
| * @return This writer instance | ||
| */ | ||
| @Override | ||
| public Writer append(final CharSequence value, final int start, final int end) { | ||
| builder.append(value, start, end); | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Closing this writer has no effect. | ||
| */ | ||
| @Override | ||
| public void close() { | ||
| // no-op | ||
| } | ||
|
|
||
| /** | ||
| * Flushing this writer has no effect. | ||
| */ | ||
| @Override | ||
| public void flush() { | ||
| // no-op | ||
| } | ||
|
|
||
| /** | ||
| * Gets the underlying builder. | ||
| * | ||
| * @return The underlying builder | ||
| */ | ||
| public StringBuilder getBuilder() { | ||
| return builder; | ||
| } | ||
|
|
||
| /** | ||
| * Returns {@link StringBuilder#toString()}. | ||
| * | ||
| * @return The contents of the String builder. | ||
| */ | ||
| @Override | ||
| public String toString() { | ||
| return builder.toString(); | ||
| } | ||
|
|
||
| /** | ||
| * Writes a portion of a character array to the {@link StringBuilder}. | ||
| * | ||
| * @param value The value to write | ||
| * @param offset The index of the first character | ||
| * @param length The number of characters to write | ||
| */ | ||
| @Override | ||
| public void write(final char[] value, final int offset, final int length) { | ||
| if (value != null) { | ||
| builder.append(value, offset, length); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Writes a String to the {@link StringBuilder}. | ||
| * | ||
| * @param value The value to write | ||
| */ | ||
| @Override | ||
| public void write(final String value) { | ||
| if (value != null) { | ||
| builder.append(value); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like Groovy, I kept the copyright notice and JavaDoc intact but removed the dependency on
IOUtils.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Build is KO due to copyright missing I guess
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@laurentschoelens yes - how shall I handle this? is it possible to add a jaxb-ri copyright to a class copied from another project? I am not a lawyer...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind, I found the
copyright-excludefile...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That’s for code which either went through legal or is non-source file. This does not satisfy any of those conditions and likely breaks existing project’s license.