Skip to content

Commit 1497142

Browse files
committed
improve performance for 2 or more turbo filters
Signed-off-by: ceki <[email protected]>
1 parent 04a7ba5 commit 1497142

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

logback-classic/src/main/java/ch/qos/logback/classic/spi/TurboFilterList.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/**
22
* Logback: the reliable, generic, fast and flexible logging framework.
33
* Copyright (C) 1999-2015, QOS.ch. All rights reserved.
4-
*
4+
* <p>
55
* This program and the accompanying materials are dual-licensed under
66
* either the terms of the Eclipse Public License v1.0 as published by
77
* the Eclipse Foundation
8-
*
9-
* or (per the licensee's choosing)
10-
*
8+
* <p>
9+
* or (per the licensee's choosing)
10+
* <p>
1111
* under the terms of the GNU Lesser General Public License version 2.1
1212
* as published by the Free Software Foundation.
1313
*/
@@ -24,7 +24,7 @@
2424

2525
/**
2626
* Implementation of TurboFilterAttachable.
27-
*
27+
*
2828
* @author Ceki G&uuml;lc&uuml;
2929
*/
3030
final public class TurboFilterList extends CopyOnWriteArrayList<TurboFilter> {
@@ -37,31 +37,32 @@ final public class TurboFilterList extends CopyOnWriteArrayList<TurboFilter> {
3737
* then NEUTRAL is returned.
3838
*/
3939
public FilterReply getTurboFilterChainDecision(final Marker marker, final Logger logger, final Level level,
40-
final String format, final Object[] params, final Throwable t) {
40+
final String format, final Object[] params, final Throwable t) {
4141

4242
final int size = size();
43-
// if (size == 0) {
44-
// return FilterReply.NEUTRAL;
45-
// }
43+
// caller may have already performed this check, but we do it here as well to be sure
44+
if (size == 0) {
45+
return FilterReply.NEUTRAL;
46+
}
47+
4648
if (size == 1) {
4749
try {
4850
TurboFilter tf = get(0);
4951
return tf.decide(marker, logger, level, format, params, t);
5052
} catch (IndexOutOfBoundsException iobe) {
53+
// concurrent modification detected, fall through to the general case
5154
return FilterReply.NEUTRAL;
5255
}
5356
}
5457

55-
Object[] tfa = toArray();
56-
final int len = tfa.length;
57-
for (int i = 0; i < len; i++) {
58-
// for (TurboFilter tf : this) {
59-
final TurboFilter tf = (TurboFilter) tfa[i];
58+
59+
for (TurboFilter tf : this) {
6060
final FilterReply r = tf.decide(marker, logger, level, format, params, t);
6161
if (r == FilterReply.DENY || r == FilterReply.ACCEPT) {
6262
return r;
6363
}
6464
}
65+
6566
return FilterReply.NEUTRAL;
6667
}
6768

logback-classic/src/main/java/ch/qos/logback/classic/turbo/TurboFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* first is much more performant.
2828
* <p>
2929
* For more information about turbo filters, please refer to the online manual
30-
* at http://logback.qos.ch/manual/filters.html#TurboFilter
30+
* at https://logback.qos.ch/manual/filters.html#TurboFilter
3131
*
3232
* @author Ceki Gulcu
3333
*/

0 commit comments

Comments
 (0)