Path: blob/main/scripts/chat-simulation/fixtures/_chatperf_uri.ts
13383 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45// perf-benchmark-marker67/**8* Fixture for chat-simulation benchmarks.9* Simplified from src/vs/base/common/uri.ts for stable perf testing.10*/1112const _empty = '';13const _slash = '/';1415export class URI {16readonly scheme: string;17readonly authority: string;18readonly path: string;19readonly query: string;20readonly fragment: string;2122private constructor(scheme: string, authority: string, path: string, query: string, fragment: string) {23this.scheme = scheme;24this.authority = authority || _empty;25this.path = path || _empty;26this.query = query || _empty;27this.fragment = fragment || _empty;28}2930static file(path: string): URI {31let authority = _empty;32if (path.length >= 2 && path.charCodeAt(0) === 47 /* / */ && path.charCodeAt(1) === 47 /* / */) {33const idx = path.indexOf(_slash, 2);34if (idx === -1) {35authority = path.substring(2);36path = _slash;37} else {38authority = path.substring(2, idx);39path = path.substring(idx) || _slash;40}41}42return new URI('file', authority, path, _empty, _empty);43}4445static parse(value: string): URI {46const match = /^([a-zA-Z][a-zA-Z0-9+.-]*):\/\/([^/?#]*)([^?#]*)(\?[^#]*)?(#.*)?$/.exec(value);47if (!match) { return new URI(_empty, _empty, _empty, _empty, _empty); }48return new URI(match[1], match[2], match[3], match[4]?.substring(1) || _empty, match[5]?.substring(1) || _empty);49}5051with(change: { scheme?: string; authority?: string; path?: string; query?: string; fragment?: string }): URI {52return new URI(53change.scheme ?? this.scheme,54change.authority ?? this.authority,55change.path ?? this.path,56change.query ?? this.query,57change.fragment ?? this.fragment,58);59}6061toString(): string {62let result = '';63if (this.scheme) { result += this.scheme + '://'; }64if (this.authority) { result += this.authority; }65if (this.path) { result += this.path; }66if (this.query) { result += '?' + this.query; }67if (this.fragment) { result += '#' + this.fragment; }68return result;69}7071get fsPath(): string {72return this.path;73}7475toJSON(): object {76return {77scheme: this.scheme,78authority: this.authority,79path: this.path,80query: this.query,81fragment: this.fragment,82};83}84}858687