优化
This commit is contained in:
@@ -144,8 +144,7 @@ class CircQueue<T> {
|
||||
Future<bool> send(T item, {int timeoutMs = 0}) async {
|
||||
final start = DateTime.now().millisecondsSinceEpoch;
|
||||
while (!enter(item)) {
|
||||
if (timeoutMs > 0 &&
|
||||
DateTime.now().millisecondsSinceEpoch - start >= timeoutMs) {
|
||||
if (timeoutMs > 0 && DateTime.now().millisecondsSinceEpoch - start >= timeoutMs) {
|
||||
return false;
|
||||
}
|
||||
await Future.delayed(const Duration(milliseconds: 1));
|
||||
@@ -159,8 +158,7 @@ class CircQueue<T> {
|
||||
while (true) {
|
||||
final item = out();
|
||||
if (item != null) return item;
|
||||
if (timeoutMs > 0 &&
|
||||
DateTime.now().millisecondsSinceEpoch - start >= timeoutMs) {
|
||||
if (timeoutMs > 0 && DateTime.now().millisecondsSinceEpoch - start >= timeoutMs) {
|
||||
return null;
|
||||
}
|
||||
await Future.delayed(const Duration(milliseconds: 1));
|
||||
@@ -198,11 +196,7 @@ class TracePoint<T> {
|
||||
|
||||
/// 构造函数
|
||||
TracePoint({int queueCapacity = 5, int maxMemoryBytes = 1024 * 1024}) {
|
||||
_queue = CircQueue<T>(
|
||||
queueCapacity,
|
||||
deepCopy: true,
|
||||
maxMemoryBytes: maxMemoryBytes,
|
||||
);
|
||||
_queue = CircQueue<T>(queueCapacity, deepCopy: true, maxMemoryBytes: maxMemoryBytes);
|
||||
_lock = TryLock();
|
||||
reset();
|
||||
}
|
||||
@@ -225,9 +219,7 @@ class TracePoint<T> {
|
||||
void upsert(T point, [TPAction act = TPAction.UPDATE]) {
|
||||
switch (_mode) {
|
||||
case TPMode.NAVIGATION:
|
||||
act == TPAction.UPDATE
|
||||
? _updateCurrentPoint(point)
|
||||
: _addCompletePoint(point);
|
||||
act == TPAction.UPDATE ? _updateCurrentPoint(point) : _addCompletePoint(point);
|
||||
break;
|
||||
case TPMode.LOCATION:
|
||||
_updateCurrentPoint(point);
|
||||
@@ -262,9 +254,7 @@ class TracePoint<T> {
|
||||
switch (_mode) {
|
||||
case TPMode.NAVIGATION:
|
||||
if (_tracePoint.isEmpty) {
|
||||
print(
|
||||
'updateCurrentPoint: tracePoint is empty , wait first completed point, discard current point: $point',
|
||||
);
|
||||
print('updateCurrentPoint: tracePoint is empty , wait first completed point, discard current point: $point');
|
||||
} else {
|
||||
_tracePoint = _tracePoint.sublist(0, _completePointIndex);
|
||||
_tracePoint.add(point);
|
||||
@@ -328,8 +318,7 @@ class TracePoint<T> {
|
||||
return;
|
||||
}
|
||||
|
||||
final hasCurrentPoint =
|
||||
_tracePoint.isNotEmpty && _completePointIndex < _tracePoint.length;
|
||||
final hasCurrentPoint = _tracePoint.isNotEmpty && _completePointIndex < _tracePoint.length;
|
||||
|
||||
if (hasCurrentPoint) {
|
||||
_tracePoint = _tracePoint.sublist(0, _completePointIndex);
|
||||
|
||||
Reference in New Issue
Block a user