made assertWriteAcquired() generate expensive garbage in tests and debug only

This commit is contained in:
Alexey Kudravtsev
2016-10-17 15:43:07 +03:00
parent c1ba655f17
commit dd6384ac01
2 changed files with 14 additions and 12 deletions
@@ -15,6 +15,8 @@
*/
package com.intellij.openapi.editor.impl;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.ex.MarkupIterator;
import com.intellij.openapi.util.Getter;
import com.intellij.util.IncorrectOperationException;
@@ -42,6 +44,8 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
* User: cdr
*/
abstract class IntervalTreeImpl<T extends MutableInterval> extends RedBlackTree<T> implements IntervalTree<T> {
static final Logger LOG = Logger.getInstance("#com.intellij.openapi.editor.impl.RangeMarkerTree");
static final boolean DEBUG = LOG.isDebugEnabled() || ApplicationManager.getApplication() != null && (ApplicationManager.getApplication().isUnitTestMode() || ApplicationManager.getApplication().isInternal());
private int keySize; // number of all intervals, counting all duplicates, some of them maybe gced
final ReadWriteLock l = new ReentrantReadWriteLock();
@@ -66,7 +70,7 @@ abstract class IntervalTreeImpl<T extends MutableInterval> extends RedBlackTree<
@NotNull
private final IntervalTreeImpl<E> myIntervalTree;
public IntervalNode(@NotNull IntervalTreeImpl<E> intervalTree, @NotNull E key, int start, int end) {
IntervalNode(@NotNull IntervalTreeImpl<E> intervalTree, @NotNull E key, int start, int end) {
// maxEnd == 0 so to not disrupt existing maxes
myIntervalTree = intervalTree;
myStart = start;
@@ -374,7 +378,9 @@ abstract class IntervalTreeImpl<T extends MutableInterval> extends RedBlackTree<
}
private void assertUnderWriteLock() {
assert isAcquired(l.writeLock()) : l.writeLock();
if (DEBUG) {
assert isAcquired(l.writeLock()) : l.writeLock();
}
}
private static boolean isAcquired(@NotNull Lock l) {
String s = l.toString();
@@ -17,7 +17,6 @@ package com.intellij.openapi.editor.impl;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.impl.ApplicationInfoImpl;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.event.DocumentEvent;
import com.intellij.openapi.editor.ex.PrioritizedDocumentListener;
@@ -38,9 +37,6 @@ import java.util.concurrent.atomic.AtomicInteger;
* User: cdr
*/
public class RangeMarkerTree<T extends RangeMarkerEx> extends IntervalTreeImpl<T> {
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.editor.impl.RangeMarkerTree");
private static final boolean DEBUG = LOG.isDebugEnabled() || ApplicationManager.getApplication() != null && (ApplicationManager.getApplication().isUnitTestMode() || ApplicationManager.getApplication().isInternal());
private final PrioritizedDocumentListener myListener;
private final Document myDocument;
@@ -159,12 +155,12 @@ public class RangeMarkerTree<T extends RangeMarkerEx> extends IntervalTreeImpl<T
private static final byte EXPAND_TO_LEFT_FLAG = VALID_FLAG<<1;
private static final byte EXPAND_TO_RIGHT_FLAG = EXPAND_TO_LEFT_FLAG<<1;
public RMNode(@NotNull RangeMarkerTree<T> rangeMarkerTree,
@NotNull T key,
int start,
int end,
boolean greedyToLeft,
boolean greedyToRight) {
RMNode(@NotNull RangeMarkerTree<T> rangeMarkerTree,
@NotNull T key,
int start,
int end,
boolean greedyToLeft,
boolean greedyToRight) {
super(rangeMarkerTree, key, start, end);
setFlag(EXPAND_TO_LEFT_FLAG, greedyToLeft);
setFlag(EXPAND_TO_RIGHT_FLAG, greedyToRight);