Skip to content

Commit a954e13

Browse files
committed
fix: use System.nanoTime in TMModel to measure elapsed time
1 parent 8f60454 commit a954e13

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

  • org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model

org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/TMModel.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ private final class TokenizerThread extends Thread {
139139
private static final Duration MAX_TIME_PER_LINE_TOKENIZATION = Duration.ofSeconds(1);
140140

141141
/** max time in milliseconds for multi-line validations before a consolidated {@link ModelTokensChangedEvent} is emitted */
142-
private static final int MAX_TIME_PER_MULTI_LINE_VALIDATIONS = 200;
142+
private static final int MAX_TIME_PER_MULTI_LINE_VALIDATIONS = Duration.ofMillis(200).getNano();
143143

144144
/** Creates a new background thread. The thread runs with minimal priority. */
145145
TokenizerThread() {
@@ -200,7 +200,7 @@ private void revalidateTokens() {
200200
logDebug("(%d)", startLineNumber);
201201
}
202202

203-
long startTime = System.currentTimeMillis();
203+
long startNanoTime = System.nanoTime();
204204
var changedRanges = new ArrayList<Range>();
205205
Range prevRange = null;
206206
var prevLineTokens = getLineTokensOrNull(startLineIndex - 1);
@@ -275,14 +275,14 @@ private void revalidateTokens() {
275275
}
276276

277277
// if MAX_TIME_PER_MULTI_LINE_VALIDATIONS reached, notify listeners about line changes
278-
if (System.currentTimeMillis() - startTime >= MAX_TIME_PER_MULTI_LINE_VALIDATIONS) {
278+
if (System.nanoTime() - startNanoTime >= MAX_TIME_PER_MULTI_LINE_VALIDATIONS) {
279279
if (DEBUG_LOGGING) {
280280
logDebug("(%d) >> changedRanges: %s", startLineNumber, changedRanges);
281281
}
282282
listeners.dispatchEvent(changedRanges, TMModel.this);
283283
changedRanges = new ArrayList<>();
284284
prevRange = null;
285-
startTime = System.currentTimeMillis();
285+
startNanoTime = System.nanoTime();
286286
}
287287
}
288288

0 commit comments

Comments
 (0)