minor fixes:

- better perf for short DCS without params (8 times faster)
- test perf for class and string based interfaces of OSC and DCS
  separately
- undo wrong commit on parser
This commit is contained in:
Jörg Breitbart
2021-01-21 15:58:03 +01:00
parent dd5b295219
commit 3f659a15da
3 changed files with 105 additions and 43 deletions
+12 -4
View File
@@ -100,19 +100,27 @@ export class DcsParser implements IDcsParser {
}
}
// predefine empty params as [0] (ZDM)
const EMPTY_PARAMS = new Params();
EMPTY_PARAMS.addParam(0);
/**
* Convenient class to create a DCS handler from a single callback function.
* Note: The payload is currently limited to 50 MB (hardcoded).
*/
export class DcsHandler implements IDcsHandler {
private _data = '';
private _params: IParams | undefined;
private _params: IParams = EMPTY_PARAMS;
private _hitLimit: boolean = false;
constructor(private _handler: (data: string, params: IParams) => boolean) {}
public hook(params: IParams): void {
this._params = params.clone();
// since we need to preserve params until `unhook`, we have to clone it
// (only borrowed from parser and spans multiple parser states)
// perf optimization:
// clone only, if we have non empty params, otherwise stick with default
this._params = (params.length > 1 || params.params[0]) ? params.clone() : EMPTY_PARAMS;
this._data = '';
this._hitLimit = false;
}
@@ -133,9 +141,9 @@ export class DcsHandler implements IDcsHandler {
if (this._hitLimit) {
ret = false;
} else if (success) {
ret = this._handler(this._data, this._params || new Params());
ret = this._handler(this._data, this._params);
}
this._params = undefined;
this._params = EMPTY_PARAMS;
this._data = '';
this._hitLimit = false;
return ret;