Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/scripts/chat-simulation/fixtures/_chatperf_uri.ts
13383 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
// perf-benchmark-marker
7
8
/**
9
* Fixture for chat-simulation benchmarks.
10
* Simplified from src/vs/base/common/uri.ts for stable perf testing.
11
*/
12
13
const _empty = '';
14
const _slash = '/';
15
16
export class URI {
17
readonly scheme: string;
18
readonly authority: string;
19
readonly path: string;
20
readonly query: string;
21
readonly fragment: string;
22
23
private constructor(scheme: string, authority: string, path: string, query: string, fragment: string) {
24
this.scheme = scheme;
25
this.authority = authority || _empty;
26
this.path = path || _empty;
27
this.query = query || _empty;
28
this.fragment = fragment || _empty;
29
}
30
31
static file(path: string): URI {
32
let authority = _empty;
33
if (path.length >= 2 && path.charCodeAt(0) === 47 /* / */ && path.charCodeAt(1) === 47 /* / */) {
34
const idx = path.indexOf(_slash, 2);
35
if (idx === -1) {
36
authority = path.substring(2);
37
path = _slash;
38
} else {
39
authority = path.substring(2, idx);
40
path = path.substring(idx) || _slash;
41
}
42
}
43
return new URI('file', authority, path, _empty, _empty);
44
}
45
46
static parse(value: string): URI {
47
const match = /^([a-zA-Z][a-zA-Z0-9+.-]*):\/\/([^/?#]*)([^?#]*)(\?[^#]*)?(#.*)?$/.exec(value);
48
if (!match) { return new URI(_empty, _empty, _empty, _empty, _empty); }
49
return new URI(match[1], match[2], match[3], match[4]?.substring(1) || _empty, match[5]?.substring(1) || _empty);
50
}
51
52
with(change: { scheme?: string; authority?: string; path?: string; query?: string; fragment?: string }): URI {
53
return new URI(
54
change.scheme ?? this.scheme,
55
change.authority ?? this.authority,
56
change.path ?? this.path,
57
change.query ?? this.query,
58
change.fragment ?? this.fragment,
59
);
60
}
61
62
toString(): string {
63
let result = '';
64
if (this.scheme) { result += this.scheme + '://'; }
65
if (this.authority) { result += this.authority; }
66
if (this.path) { result += this.path; }
67
if (this.query) { result += '?' + this.query; }
68
if (this.fragment) { result += '#' + this.fragment; }
69
return result;
70
}
71
72
get fsPath(): string {
73
return this.path;
74
}
75
76
toJSON(): object {
77
return {
78
scheme: this.scheme,
79
authority: this.authority,
80
path: this.path,
81
query: this.query,
82
fragment: this.fragment,
83
};
84
}
85
}
86
87