Skip to content

Commit

Permalink
Use Map instead of Record.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlemstra committed Jan 15, 2025
1 parent 78c2a27 commit 0f54b59
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/statistics/statistics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,18 @@ export interface IStatistics {

/** @internal */
export class Statistics implements IStatistics {
private _channels: Record<number, ChannelStatistics> = {};
private readonly _channels: Map<PixelChannel, ChannelStatistics> = new Map();

get channels(): ReadonlyArray<PixelChannel> {
const channels: PixelChannel[] = [];
for (const channel in this._channels) {
channels.push(parseInt(channel));
}

return channels;
return Array.from(this._channels.keys());
}

composite(): IChannelStatistics {
return this._channels[PixelChannel.Composite];
return this._channels.get(PixelChannel.Composite)!;
}

getChannel(channel: PixelChannel): IChannelStatistics | null {
const channelStatistics = this._channels[channel];
const channelStatistics = this._channels.get(channel);
return channelStatistics !== undefined ? channelStatistics : null;
}

Expand All @@ -68,7 +63,7 @@ export class Statistics implements IStatistics {
private addChannel(list: number, channel: PixelChannel) {
const instance = ImageMagick._api._Statistics_GetInstance(list, channel);
if (instance !== 0) {
this._channels[channel] = new ChannelStatistics(channel, instance);
this._channels.set(channel, new ChannelStatistics(channel, instance));
}
}
}

0 comments on commit 0f54b59

Please sign in to comment.