You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rp...@apache.org on 2016/03/14 17:22:59 UTC
logging-log4j2 git commit: LOG4J2-1296 refactor magic numbers to
constants
Repository: logging-log4j2
Updated Branches:
refs/heads/master 69999c227 -> 50c76834e
LOG4J2-1296 refactor magic numbers to constants
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/50c76834
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/50c76834
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/50c76834
Branch: refs/heads/master
Commit: 50c76834e7fbc878652d8d983738c9369f3158ec
Parents: 69999c2
Author: rpopma <rp...@apache.org>
Authored: Tue Mar 15 03:22:58 2016 +1100
Committer: rpopma <rp...@apache.org>
Committed: Tue Mar 15 03:22:58 2016 +1100
----------------------------------------------------------------------
.../logging/log4j/core/async/RingBufferLogEvent.java | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/50c76834/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
index 32d73d9..e4c135a 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
@@ -46,6 +46,8 @@ public class RingBufferLogEvent implements LogEvent {
public static final Factory FACTORY = new Factory();
private static final long serialVersionUID = 8462119088943934758L;
+ private static final int INITIAL_REUSABLE_MESSAGE_SIZE = 128;
+ private static final int MAX_REUSABLE_MESSAGE_SIZE = 128 * 2 + 2; // resized once from 128 (s=s*2+2)
/**
* Creates the events that will be put in the RingBuffer.
@@ -56,7 +58,7 @@ public class RingBufferLogEvent implements LogEvent {
public RingBufferLogEvent newInstance() {
RingBufferLogEvent result = new RingBufferLogEvent();
if (Constants.ENABLE_THREADLOCALS) {
- result.messageText = new StringBuilder(128);
+ result.messageText = new StringBuilder(INITIAL_REUSABLE_MESSAGE_SIZE);
}
return result;
}
@@ -91,8 +93,8 @@ public class RingBufferLogEvent implements LogEvent {
buffer.append(stringBuilder);
// ensure that excessively long char[] arrays are not kept in memory forever
- if (stringBuilder.length() > 518) { // resized twice from 128 (s=s*2+2)
- stringBuilder.setLength(518);
+ if (stringBuilder.length() > MAX_REUSABLE_MESSAGE_SIZE) {
+ stringBuilder.setLength(MAX_REUSABLE_MESSAGE_SIZE);
stringBuilder.trimToSize();
}
}
@@ -136,7 +138,7 @@ public class RingBufferLogEvent implements LogEvent {
if (messageText == null) {
// Should never happen:
// only happens if user logs a custom reused message when Constants.ENABLE_THREADLOCALS is false
- messageText = new StringBuilder(128);
+ messageText = new StringBuilder(INITIAL_REUSABLE_MESSAGE_SIZE);
}
messageText.setLength(0);
((ReusableMessage) msg).formatTo(messageText);
@@ -340,8 +342,8 @@ public class RingBufferLogEvent implements LogEvent {
);
// ensure that excessively long char[] arrays are not kept in memory forever
- if (messageText != null && messageText.length() > 258) { // resized more than once from 128 (s=s*2+2)
- messageText.setLength(258);
+ if (messageText != null && messageText.length() > MAX_REUSABLE_MESSAGE_SIZE) {
+ messageText.setLength(MAX_REUSABLE_MESSAGE_SIZE);
messageText.trimToSize();
}
}