stream_data: Make slug regex a bit more readable.

This clarifies that the second group is purely for use internal
to the regexp (it's there for the ? to act on) and won't be saved
as a substring for the surrounding code to look at (like match[2]).
In a hot path that could be a performance savings; here it just
makes things a bit more explicit for the reader.
This commit is contained in:
evykassirer
2024-09-17 14:54:33 -07:00
committed by Tim Abbott
parent 7a6135371e
commit 2ad1dc7014

View File

@@ -271,7 +271,7 @@ export function slug_to_stream_id(slug: string): number | undefined {
*/
// "New" (2018) format: ${stream_id}-${stream_name} .
const match = /^(\d+)(-.*)?$/.exec(slug);
const match = /^(\d+)(?:-.*)?$/.exec(slug);
const newFormatStreamId = match ? Number.parseInt(match[1]!, 10) : null;
if (newFormatStreamId && stream_info.get(newFormatStreamId)) {
return newFormatStreamId;