Skip to content

Commit 6c1547a

Browse files
committed
Avoid getting container's element type two times
1 parent 70ff6f7 commit 6c1547a

File tree

1 file changed

+11
-32
lines changed

1 file changed

+11
-32
lines changed

src/loader.ts

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ export class Loader {
374374
export class ContainerLoader extends Loader {}
375375

376376
export class Numbers extends ContainerLoader {
377-
constructor(private _container: Container) {
377+
constructor(private _container: Container, private _numberType: string) {
378378
super();
379379
}
380380
async load(dbg: debug.Debugger, variable: Variable): Promise<draw.Drawable | undefined> {
@@ -391,20 +391,13 @@ export class Numbers extends ContainerLoader {
391391
}
392392

393393
export class Values extends ContainerLoader {
394-
constructor(private _container: Container, private _value: Value) {
394+
constructor(private _container: Container, private _value: Value, private _valueType: string) {
395395
super();
396396
}
397397
async load(dbg: debug.Debugger, variable: Variable): Promise<draw.Drawable | undefined> {
398-
const elStr = this._container.element(variable);
399-
if (elStr === undefined)
400-
return undefined;
401-
const elType = await dbg.getRawType(elStr);
402-
if (elType === undefined)
403-
return undefined;
404398
let ys: number[] = [];
405-
let v = new Variable(elStr, elType);
406399
for await (let elStr of this._container.elements(dbg, variable)) {
407-
v.name = elStr;
400+
const v = new Variable(elStr, this._valueType);
408401
const n = await this._value.load(dbg, v);
409402
if (n === undefined)
410403
return undefined
@@ -415,22 +408,15 @@ export class Values extends ContainerLoader {
415408
}
416409

417410
export class Points extends ContainerLoader {
418-
constructor(private _container: Container, private _point: Point) {
411+
constructor(private _container: Container, private _point: Point, private _pointType: string) {
419412
super();
420413
}
421414
async load(dbg: debug.Debugger, variable: Variable): Promise<draw.Drawable | undefined> {
422-
const elStr = this._container.element(variable);
423-
if (elStr === undefined)
424-
return undefined;
425-
const elType = await dbg.getRawType(elStr);
426-
if (elType === undefined)
427-
return undefined;
428415
let xs: number[] = [];
429416
let ys: number[] = [];
430-
let v = new Variable(elStr, elType);
431417
let system = draw.System.None;
432418
for await (let elStr of this._container.elements(dbg, variable)) {
433-
v.name = elStr;
419+
let v = new Variable(elStr, this._pointType);
434420
const point = await this._point.load(dbg, v);
435421
if (point === undefined)
436422
return undefined;
@@ -444,20 +430,13 @@ export class Points extends ContainerLoader {
444430
}
445431

446432
export class Geometries extends ContainerLoader {
447-
constructor(private _container: Container, private _geometry: Geometry) {
433+
constructor(private _container: Container, private _geometry: Geometry, private _geometryType: string) {
448434
super();
449435
}
450436
async load(dbg: debug.Debugger, variable: Variable): Promise<draw.Drawable | undefined> {
451-
const elStr = this._container.element(variable);
452-
if (elStr === undefined)
453-
return undefined;
454-
const elType = await dbg.getRawType(elStr);
455-
if (elType === undefined)
456-
return undefined;
457437
let drawables: draw.Drawable[] = [];
458-
let v = new Variable(elStr, elType);
459438
for await (let elStr of this._container.elements(dbg, variable)) {
460-
v.name = elStr;
439+
const v = new Variable(elStr, this._geometryType);
461440
const d = await this._geometry.load(dbg, v);
462441
if (d === undefined)
463442
return undefined;
@@ -1226,15 +1205,15 @@ async function getElements(dbg: debug.Debugger,
12261205
const elemVar = new Variable(elemStr, elemType);
12271206
const elemLoad = await getLoader(dbg, elemVar, elemKindPred);
12281207
if (elemLoad instanceof Point)
1229-
return new Points(container, elemLoad);
1208+
return new Points(container, elemLoad, elemType);
12301209
else if (elemLoad instanceof Geometry)
1231-
return new Geometries(container, elemLoad);
1210+
return new Geometries(container, elemLoad, elemType);
12321211
if (elemKindPred('value')) {
12331212
const valLoad = await getValue(dbg, elemVar);
12341213
if (valLoad instanceof Value)
1235-
return new Values(container, valLoad);
1214+
return new Values(container, valLoad, elemType);
12361215
// Assume it's a container of numbers
1237-
return new Numbers(container);
1216+
return new Numbers(container, elemType);
12381217
}
12391218
}
12401219
}

0 commit comments

Comments
 (0)