Avoid property use and float->number conversion
This commit is contained in:
+14
-3
@@ -8,6 +8,8 @@ import { addDisposableDomListener } from 'browser/Lifecycle';
|
|||||||
import { IColorSet, IViewport } from 'browser/Types';
|
import { IColorSet, IViewport } from 'browser/Types';
|
||||||
import { ICharSizeService, IRenderService } from 'browser/services/Services';
|
import { ICharSizeService, IRenderService } from 'browser/services/Services';
|
||||||
import { IBufferService, IOptionsService } from 'common/services/Services';
|
import { IBufferService, IOptionsService } from 'common/services/Services';
|
||||||
|
import { IBuffer } from 'common/buffer/Types';
|
||||||
|
import { IRenderDimensions } from 'browser/renderer/Types';
|
||||||
|
|
||||||
const FALLBACK_SCROLL_BAR_WIDTH = 15;
|
const FALLBACK_SCROLL_BAR_WIDTH = 15;
|
||||||
|
|
||||||
@@ -18,12 +20,15 @@ const FALLBACK_SCROLL_BAR_WIDTH = 15;
|
|||||||
export class Viewport extends Disposable implements IViewport {
|
export class Viewport extends Disposable implements IViewport {
|
||||||
public scrollBarWidth: number = 0;
|
public scrollBarWidth: number = 0;
|
||||||
private _currentRowHeight: number = 0;
|
private _currentRowHeight: number = 0;
|
||||||
|
private _currentScaledCellHeight: number = 0;
|
||||||
private _lastRecordedBufferLength: number = 0;
|
private _lastRecordedBufferLength: number = 0;
|
||||||
private _lastRecordedViewportHeight: number = 0;
|
private _lastRecordedViewportHeight: number = 0;
|
||||||
private _lastRecordedBufferHeight: number = 0;
|
private _lastRecordedBufferHeight: number = 0;
|
||||||
private _lastTouchY: number = 0;
|
private _lastTouchY: number = 0;
|
||||||
private _lastScrollTop: number = 0;
|
private _lastScrollTop: number = 0;
|
||||||
private _lastHadScrollBar: boolean = false;
|
private _lastHadScrollBar: boolean = false;
|
||||||
|
private _activeBuffer: IBuffer;
|
||||||
|
private _renderDimensions: IRenderDimensions;
|
||||||
|
|
||||||
// Stores a partial line amount when scrolling, this is used to keep track of how much of a line
|
// Stores a partial line amount when scrolling, this is used to keep track of how much of a line
|
||||||
// is scrolled so we can "scroll" over partial lines and feel natural on touchpads. This is a
|
// is scrolled so we can "scroll" over partial lines and feel natural on touchpads. This is a
|
||||||
@@ -51,6 +56,12 @@ export class Viewport extends Disposable implements IViewport {
|
|||||||
this._lastHadScrollBar = true;
|
this._lastHadScrollBar = true;
|
||||||
this.register(addDisposableDomListener(this._viewportElement, 'scroll', this._onScroll.bind(this)));
|
this.register(addDisposableDomListener(this._viewportElement, 'scroll', this._onScroll.bind(this)));
|
||||||
|
|
||||||
|
// Track properties used in performance critical code manually to avoid using slow getters
|
||||||
|
this._activeBuffer = this._bufferService.buffer;
|
||||||
|
this.register(this._bufferService.buffers.onBufferActivate(e => this._activeBuffer = e.activeBuffer));
|
||||||
|
this._renderDimensions = this._renderService.dimensions;
|
||||||
|
this.register(this._renderService.onDimensionsChange(e => this._renderDimensions = e));
|
||||||
|
|
||||||
// Perform this async to ensure the ICharSizeService is ready.
|
// Perform this async to ensure the ICharSizeService is ready.
|
||||||
setTimeout(() => this.syncScrollArea(), 0);
|
setTimeout(() => this.syncScrollArea(), 0);
|
||||||
}
|
}
|
||||||
@@ -79,6 +90,7 @@ export class Viewport extends Disposable implements IViewport {
|
|||||||
private _innerRefresh(): void {
|
private _innerRefresh(): void {
|
||||||
if (this._charSizeService.height > 0) {
|
if (this._charSizeService.height > 0) {
|
||||||
this._currentRowHeight = this._renderService.dimensions.scaledCellHeight / window.devicePixelRatio;
|
this._currentRowHeight = this._renderService.dimensions.scaledCellHeight / window.devicePixelRatio;
|
||||||
|
this._currentScaledCellHeight = this._renderService.dimensions.scaledCellHeight;
|
||||||
this._lastRecordedViewportHeight = this._viewportElement.offsetHeight;
|
this._lastRecordedViewportHeight = this._viewportElement.offsetHeight;
|
||||||
const newBufferHeight = Math.round(this._currentRowHeight * this._lastRecordedBufferLength) + (this._lastRecordedViewportHeight - this._renderService.dimensions.canvasHeight);
|
const newBufferHeight = Math.round(this._currentRowHeight * this._lastRecordedBufferLength) + (this._lastRecordedViewportHeight - this._renderService.dimensions.canvasHeight);
|
||||||
if (this._lastRecordedBufferHeight !== newBufferHeight) {
|
if (this._lastRecordedBufferHeight !== newBufferHeight) {
|
||||||
@@ -126,8 +138,7 @@ export class Viewport extends Disposable implements IViewport {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If the buffer position doesn't match last scroll top
|
// If the buffer position doesn't match last scroll top
|
||||||
const newScrollTop = this._bufferService.buffer.ydisp * this._currentRowHeight;
|
if (this._lastScrollTop !== this._activeBuffer.ydisp * this._currentRowHeight) {
|
||||||
if (this._lastScrollTop !== newScrollTop) {
|
|
||||||
this._refresh(immediate);
|
this._refresh(immediate);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -139,7 +150,7 @@ export class Viewport extends Disposable implements IViewport {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If row height changed
|
// If row height changed
|
||||||
if (this._renderService.dimensions.scaledCellHeight / window.devicePixelRatio !== this._currentRowHeight) {
|
if (this._renderDimensions.scaledCellHeight !== this._currentScaledCellHeight) {
|
||||||
this._refresh(immediate);
|
this._refresh(immediate);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user