Skip to content

Commit f4c6a5c

Browse files
committed
moved iddispenser into common location
1 parent cfc67fc commit f4c6a5c

5 files changed

Lines changed: 36 additions & 35 deletions

File tree

src/client/common/idDispenser.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
export class IdDispenser {
2+
private _freedInts: number[] = [];
3+
private _curValue: number = 0;
4+
5+
public Allocate(): number {
6+
if (this._freedInts.length > 0) {
7+
let res: number = this._freedInts[this._freedInts.length - 1];
8+
this._freedInts.splice(this._freedInts.length - 1, 1);
9+
return res;
10+
} else {
11+
let res: number = this._curValue++;
12+
return res;
13+
}
14+
}
15+
16+
public Free(id: number) {
17+
if (id + 1 === this._curValue) {
18+
this._curValue--;
19+
} else {
20+
this._freedInts.push(id);
21+
}
22+
}
23+
}

src/client/debugger/Common/Utils.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -66,26 +66,3 @@ export function FixupEscapedUnicodeChars(value: string): string {
6666
return value;
6767
}
6868

69-
export class IdDispenser {
70-
private _freedInts: number[] = [];
71-
private _curValue: number = 0;
72-
73-
public Allocate(): number {
74-
if (this._freedInts.length > 0) {
75-
let res: number = this._freedInts[this._freedInts.length - 1];
76-
this._freedInts.splice(this._freedInts.length - 1, 1);
77-
return res;
78-
} else {
79-
let res: number = this._curValue++;
80-
return res;
81-
}
82-
}
83-
84-
public Free(id: number) {
85-
if (id + 1 === this._curValue) {
86-
this._curValue--;
87-
} else {
88-
this._freedInts.push(id);
89-
}
90-
}
91-
}

src/client/debugger/PythonProcess.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {FrameKind, IPythonProcess, IPythonThread, IPythonModule, IPythonEvaluati
66
import {IPythonBreakpoint, PythonBreakpointConditionKind, PythonBreakpointPassCountKind, IBreakpointCommand, IChildEnumCommand} from "./Common/Contracts";
77
import {PythonEvaluationResultReprKind, IExecutionCommand, enum_EXCEPTION_STATE} from "./Common/Contracts";
88
import {Commands} from "./ProxyCommands";
9-
import * as utils from "./Common/Utils";
9+
import {IdDispenser} from "../common/idDispenser";
1010
import {PythonProcessCallbackHandler} from "./PythonProcessCallbackHandler";
1111
import {SocketStream} from "../common/comms/SocketStream";
1212

@@ -34,7 +34,7 @@ export class PythonProcess extends EventEmitter implements IPythonProcess {
3434
public get LastExecutedThread(): IPythonThread {
3535
return this._lastExecutedThread;
3636
}
37-
private _idDispenser: utils.IdDispenser;
37+
private _idDispenser: IdDispenser;
3838
private _threads: Map<number, IPythonThread>;
3939
public get Threads(): Map<number, IPythonThread> {
4040
return this._threads;
@@ -54,7 +54,7 @@ export class PythonProcess extends EventEmitter implements IPythonProcess {
5454
this.id = id;
5555
this.guid = guid;
5656
this._threads = new Map<number, IPythonThread>();
57-
this._idDispenser = new utils.IdDispenser();
57+
this._idDispenser = new IdDispenser();
5858
this.PendingChildEnumCommands = new Map<number, IChildEnumCommand>();
5959
this.PendingExecuteCommands = new Map<number, IExecutionCommand>();
6060
this.programDirectory = programDirectory;

src/client/debugger/PythonProcessCallbackHandler.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
"use strict";
22

3-
import {FrameKind, IPythonProcess, IPythonThread, IPythonModule, IPythonEvaluationResult, IPythonStackFrame} from "./Common/Contracts";
4-
import {IDjangoStackFrame, PythonEvaluationResultFlags, PythonLanguageVersion, IChildEnumCommand, IPythonException, IExecutionCommand} from "./Common/Contracts";
3+
import { FrameKind, IPythonProcess, IPythonThread, IPythonModule, IPythonEvaluationResult, IPythonStackFrame } from "./Common/Contracts";
4+
import { IDjangoStackFrame, PythonEvaluationResultFlags, PythonLanguageVersion, IChildEnumCommand, IPythonException, IExecutionCommand } from "./Common/Contracts";
55
import * as utils from "./Common/Utils";
6-
import {EventEmitter} from "events";
7-
import {Commands} from "./ProxyCommands";
8-
import {SocketStream} from "../common/comms/SocketStream";
9-
import {ExtractTryStatements} from "./Common/TryParser";
6+
import { EventEmitter } from "events";
7+
import { Commands } from "./ProxyCommands";
8+
import { SocketStream } from "../common/comms/SocketStream";
9+
import { ExtractTryStatements } from "./Common/TryParser";
1010
import * as path from "path";
11+
import {IdDispenser} from '../common/idDispenser';
1112

1213
export class PythonProcessCallbackHandler extends EventEmitter {
1314
private process: IPythonProcess;
14-
private idDispenser: utils.IdDispenser;
15+
private idDispenser: IdDispenser;
1516
private stream: SocketStream;
1617
private _stoppedForException: boolean;
17-
constructor(process: IPythonProcess, stream: SocketStream, idDispenser: utils.IdDispenser) {
18+
constructor(process: IPythonProcess, stream: SocketStream, idDispenser: IdDispenser) {
1819
super();
1920
this.process = process;
2021
this.stream = stream;

src/client/jupyter/comms/ipythonAdapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { SocketCallbackHandler } from "../../common/comms/socketCallbackHandler"
55
import { Commands, ResponseCommands } from "./commands";
66
import { SocketStream } from "../../Common/comms/SocketStream";
77
import { SocketServer } from '../../common/comms/socketServer';
8-
import { IdDispenser } from '../../debugger/Common/Utils';
8+
import { IdDispenser } from '../../common/idDispenser';
99
import { createDeferred, Deferred } from '../../common/helpers';
1010

1111
export class iPythonAdapter extends SocketCallbackHandler {

0 commit comments

Comments
 (0)