You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-25 05:23:13 +03:00
Merge branch 'master' into develop
This commit is contained in:
24
src/utils.ts
24
src/utils.ts
@@ -28,6 +28,30 @@ import { MatrixClient, MatrixEvent } from ".";
|
||||
import { M_TIMESTAMP } from "./@types/location";
|
||||
import { ReceiptType } from "./@types/read_receipts";
|
||||
|
||||
const interns = new Map<string, string>();
|
||||
|
||||
/**
|
||||
* Internalises a string, reusing a known pointer or storing the pointer
|
||||
* if needed for future strings.
|
||||
* @param str The string to internalise.
|
||||
* @returns The internalised string.
|
||||
*/
|
||||
export function internaliseString(str: string): string {
|
||||
// Unwrap strings before entering the map, if we somehow got a wrapped
|
||||
// string as our input. This should only happen from tests.
|
||||
if ((str as unknown) instanceof String) {
|
||||
str = str.toString();
|
||||
}
|
||||
|
||||
// Check the map to see if we can store the value
|
||||
if (!interns.has(str)) {
|
||||
interns.set(str, str);
|
||||
}
|
||||
|
||||
// Return any cached string reference
|
||||
return interns.get(str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode a dictionary of query parameters.
|
||||
* Omits any undefined/null values.
|
||||
|
||||
Reference in New Issue
Block a user