Avoid java.util.stream.Stream usage in hot paths
Prior to this commit, profiling sessions would show that using `java.util.stream.Stream` in some hot code paths creates significant garbage. Where streams aren't really required, this commit turns those snippets into imperative logic because those are likely to be called once or multiple times per request. Closes gh-22341
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -141,15 +141,17 @@ public class ReactiveAdapterRegistry {
|
||||
if (clazz == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.adapters.stream()
|
||||
.filter(adapter -> adapter.getReactiveType() == clazz)
|
||||
.findFirst()
|
||||
.orElseGet(() ->
|
||||
this.adapters.stream()
|
||||
.filter(adapter -> adapter.getReactiveType().isAssignableFrom(clazz))
|
||||
.findFirst()
|
||||
.orElse(null));
|
||||
for(ReactiveAdapter adapter : this.adapters) {
|
||||
if (adapter.getReactiveType() == clazz) {
|
||||
return adapter;
|
||||
}
|
||||
}
|
||||
for(ReactiveAdapter adapter : this.adapters) {
|
||||
if (adapter.getReactiveType().isAssignableFrom(clazz)) {
|
||||
return adapter;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -74,7 +74,12 @@ public abstract class AbstractEncoder<T> implements Encoder<T> {
|
||||
if (mimeType == null) {
|
||||
return true;
|
||||
}
|
||||
return this.encodableMimeTypes.stream().anyMatch(candidate -> candidate.isCompatibleWith(mimeType));
|
||||
for(MimeType candidate : this.encodableMimeTypes) {
|
||||
if (candidate.isCompatibleWith(mimeType)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -63,7 +63,12 @@ final class CompositeLog implements Log {
|
||||
}
|
||||
|
||||
private static Log initLogger(List<Log> loggers, Predicate<Log> predicate) {
|
||||
return loggers.stream().filter(predicate).findFirst().orElse(NO_OP_LOG);
|
||||
for (Log logger : loggers) {
|
||||
if (predicate.test(logger)) {
|
||||
return logger;
|
||||
}
|
||||
}
|
||||
return NO_OP_LOG;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user