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

Add QueryParams which deprecates HttpParameters #2307

Merged
merged 49 commits into from
Dec 20, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
959f402
Add `QueryParams` which deprecates `HttpParameters`
trustin Dec 10, 2019
dfa5d11
Merge branch 'master' into immutable_http_params
trustin Dec 11, 2019
eb6bf37
Checkstyle
trustin Dec 11, 2019
8c47f62
Share the common logic between `QueryParamsBase` and `HttpHeadersBase`
trustin Dec 11, 2019
a70b113
Add some tests to ensure API consistency
trustin Dec 11, 2019
7863cca
Fix test failure
trustin Dec 11, 2019
6687a81
Rename a bunch of stuff for consistency
trustin Dec 11, 2019
acea7ff
Fix import
trustin Dec 11, 2019
48751d6
AbstractStringMultimapBuilder -> StringMultimapBuilder
trustin Dec 11, 2019
f7ae4e9
Add `QueryParamGetters.toQueryString()` and `appendQueryString()`
trustin Dec 12, 2019
5613b6d
Checkstyle and cleanup
trustin Dec 12, 2019
3f5a874
Documentation
trustin Dec 12, 2019
79ffa65
Add Javadoc return tag
trustin Dec 12, 2019
4a27a93
Merge branch 'master' into immutable_http_params
trustin Dec 14, 2019
c3ea71c
Address the comments from @anuraaga and @ikhoon
trustin Dec 14, 2019
b8c6d5e
Fix comment, inspired by @ikhoon's comment
trustin Dec 14, 2019
3663f03
Checkstyle
trustin Dec 14, 2019
b365e6d
Clean-up
trustin Dec 15, 2019
df1a365
Address the comments from @minwoox
trustin Dec 16, 2019
a041106
Address one more comment from @minwoox
trustin Dec 16, 2019
c5c096a
Address yet another comment from @minwoox
trustin Dec 16, 2019
7eea42f
Address some of the comments from @anuraaga
trustin Dec 16, 2019
39521ff
Replace `ThreadLocalByteArray` with `TemporaryThreadLocals` / Optimiz…
trustin Dec 16, 2019
ce90fe5
Optimization
trustin Dec 17, 2019
bfd2196
Simplify
trustin Dec 17, 2019
0ef906b
Clean-up
trustin Dec 18, 2019
1bc56ae
Fix encoder bug / Optimize decoder / More tests
trustin Dec 18, 2019
b8c5e91
Add benchmark for `QueryStringDecoder`
trustin Dec 18, 2019
937779c
Switch to traditional decoding loop as advised by @anuraaga
trustin Dec 18, 2019
2cac19f
Optimization and fix
trustin Dec 18, 2019
266cdc2
Further optimization of ASCII decoding
trustin Dec 18, 2019
9240e84
Optimize the decoder tad bit more, allowing us to win at any case
trustin Dec 18, 2019
b4956d0
Slightly more compact lookup table
trustin Dec 18, 2019
47f448d
Use `hashName()` instead of `.hashCode()` for names
trustin Dec 18, 2019
1e78f95
Clean-up benchmarks and add test for long query string
trustin Dec 18, 2019
e44d3b3
Improve safe octet scanning in `QueryStringEncoder` as advised by @an…
trustin Dec 18, 2019
ba0e903
Optimize percent encoding
trustin Dec 18, 2019
3d9123c
Borrow more from Guava
trustin Dec 18, 2019
c67ffb7
Checkstyle
trustin Dec 18, 2019
541796b
Experiment: Pre-inflate `StringBuilder`
trustin Dec 18, 2019
fd1c4e5
Micro clean-up
trustin Dec 18, 2019
c399ff9
Checkstyle
trustin Dec 19, 2019
8383ef9
Experiment: Make `char[]` stack-allocated by JVM
trustin Dec 19, 2019
5d17e4a
Checkstyle
trustin Dec 19, 2019
959793f
Merge branches
trustin Dec 19, 2019
59b00d5
Add Guava copyright header
trustin Dec 19, 2019
5b7dfaf
Checkstyle
trustin Dec 19, 2019
1cb66cb
Address the comments from @anuraaga
trustin Dec 19, 2019
4ae61e4
Address the comments from @minwoox
trustin Dec 20, 2019
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
Prev Previous commit
Next Next commit
Address the comments from @anuraaga and @ikhoon
  • Loading branch information
trustin committed Dec 14, 2019
commit c3ea71c9550bf17eac9efd5c86ba99919f57436f
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.linecorp.armeria.common;

import static java.util.Objects.requireNonNull;

import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
Expand Down Expand Up @@ -334,6 +336,7 @@ default Stream<Entry<AsciiString, String>> stream() {
*/
@Override
default Stream<String> valueStream(CharSequence name) {
requireNonNull(name, "name");
return Streams.stream(valueIterator(name));
trustin marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
* a new {@link HttpHeaders} derived from an existing one:</p>
*
* <pre>{@code
* HttpHeaders headers = HttpHeaders.of("name1", "value0")
* HttpHeaders headers = HttpHeaders.of("name1", "value0");
*
* // Using toBuilder()
* HttpHeaders headersWithToBuilder = headers.toBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ int hashName(CharSequence name) {
}

@Override
boolean nameEquals(@Nullable AsciiString a, @Nullable CharSequence b) {
return a != null && (a == b || a.contentEqualsIgnoreCase(b));
boolean nameEquals(AsciiString a, CharSequence b) {
return a.contentEqualsIgnoreCase(b);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ default Stream<Entry<String, String>> stream() {
*/
@Override
default Stream<String> valueStream(String name) {
requireNonNull(name, "name");
return Streams.stream(valueIterator(name));
trustin marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
* a new {@link QueryParams} derived from an existing one:</p>
*
* <pre>{@code
* QueryParams params = QueryParams.of("name1", "value0")
* QueryParams params = QueryParams.of("name1", "value0");
*
* // Using toBuilder()
* QueryParams paramsWithToBuilder = params.toBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
*/
package com.linecorp.armeria.common;

import java.util.Objects;

import javax.annotation.Nullable;

/**
Expand All @@ -56,8 +54,8 @@ int hashName(String s) {
}

@Override
boolean nameEquals(@Nullable String a, @Nullable String b) {
return Objects.equals(a, b);
boolean nameEquals(String a, String b) {
return a.equals(b);
trustin marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
Expand Down
72 changes: 50 additions & 22 deletions core/src/main/java/com/linecorp/armeria/common/StringMultimap.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ abstract class StringMultimap<IN_NAME extends CharSequence, NAME extends IN_NAME

abstract int hashName(IN_NAME name);
trustin marked this conversation as resolved.
Show resolved Hide resolved

abstract boolean nameEquals(@Nullable NAME a, @Nullable IN_NAME b);
abstract boolean nameEquals(NAME a, IN_NAME b);

abstract boolean isFirstGroup(NAME name);

Expand All @@ -150,8 +150,11 @@ public final String get(IN_NAME name) {
String value = null;
// loop until the first entry was found
while (e != null) {
if (e.hash == h && nameEquals(e.key, name)) {
value = e.value;
if (e.hash == h) {
final NAME currentName = e.key;
if (currentName != null && nameEquals(currentName, name)) {
value = e.value;
}
}
e = e.next;
}
Expand Down Expand Up @@ -182,8 +185,11 @@ private ImmutableList<String> getAllReversed(IN_NAME name) {

final ImmutableList.Builder<String> builder = ImmutableList.builder();
do {
if (e.hash == h && nameEquals(e.key, name)) {
builder.add(e.getValue());
if (e.hash == h) {
final NAME currentName = e.key;
if (currentName != null && nameEquals(currentName, name)) {
builder.add(e.getValue());
}
}
e = e.next;
} while (e != null);
Expand Down Expand Up @@ -263,8 +269,11 @@ public final boolean contains(IN_NAME name) {
Entry e = entries[i];
// loop until the first entry was found
trustin marked this conversation as resolved.
Show resolved Hide resolved
while (e != null) {
if (e.hash == h && nameEquals(e.key, name)) {
return true;
if (e.hash == h) {
final NAME currentName = e.key;
if (currentName != null && nameEquals(currentName, name)) {
return true;
}
}
e = e.next;
}
Expand All @@ -279,9 +288,12 @@ public final boolean contains(IN_NAME name, String value) {
final int i = index(h);
Entry e = entries[i];
while (e != null) {
if (e.hash == h && nameEquals(e.key, name) &&
AsciiString.contentEquals(e.value, value)) {
return true;
if (e.hash == h) {
final NAME currentName = e.key;
if (currentName != null && nameEquals(currentName, name) &&
AsciiString.contentEquals(e.value, value)) {
return true;
}
}
e = e.next;
}
Expand Down Expand Up @@ -785,11 +797,16 @@ private String remove0(int h, int i, IN_NAME name) {
String value = null;
Entry next = e.next;
while (next != null) {
if (next.hash == h && nameEquals(next.key, name)) {
value = next.value;
e.next = next.next;
next.remove();
--size;
if (next.hash == h) {
final NAME currentName = next.key;
if (currentName != null && nameEquals(currentName, name)) {
value = next.value;
e.next = next.next;
next.remove();
--size;
} else {
e = next;
}
} else {
e = next;
}
Expand All @@ -798,13 +815,16 @@ private String remove0(int h, int i, IN_NAME name) {
}

e = entries[i];
if (e.hash == h && nameEquals(e.key, name)) {
if (value == null) {
value = e.value;
if (e.hash == h) {
final NAME currentName = e.key;
if (currentName != null && nameEquals(currentName, name)) {
if (value == null) {
value = e.value;
}
entries[i] = e.next;
e.remove();
--size;
}
entries[i] = e.next;
e.remove();
--size;
}

return value;
Expand Down Expand Up @@ -1077,8 +1097,16 @@ public boolean equals(@Nullable Object o) {

@SuppressWarnings("unchecked")
final Map.Entry<IN_NAME, String> that = (Map.Entry<IN_NAME, String>) o;
final NAME thisKey = key;
final IN_NAME thatKey = that.getKey();
return nameEquals(key, thatKey) && Objects.equals(value, that.getValue());
if (thisKey == null) {
return thatKey == null &&
Objects.equals(value, that.getValue());
} else {
return thatKey != null &&
nameEquals(thisKey, thatKey) &&
Objects.equals(value, that.getValue());
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.linecorp.armeria.common;

import static java.util.Objects.requireNonNull;

import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
Expand Down Expand Up @@ -96,11 +98,7 @@ interface StringMultimapGetters<IN_NAME extends CharSequence, NAME extends IN_NA

void forEachValue(IN_NAME name, Consumer<String> action);

default Stream<Entry<NAME, String>> stream() {
return Streams.stream(iterator());
}
Stream<Entry<NAME, String>> stream();

default Stream<String> valueStream(IN_NAME name) {
return Streams.stream(valueIterator(name));
}
Stream<String> valueStream(IN_NAME name);
}