Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
26afa892
Unverified
Commit
26afa892
authored
May 02, 2026
by
Matt Mastracci
Committed by
GitHub
May 02, 2026
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace Lazy<FxHashMap> static lookups with phf::Map (#93096)
## What Trivial change: LazyLock<FxHashMap<...>> -> phf::Map.
parent
908717af
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
47 additions
and
64 deletions
+47
-64
Cargo.lock
Cargo.lock
+2
-1
Cargo.toml
crates/next-core/Cargo.toml
+1
-0
mod.rs
crates/next-core/src/next_app/metadata/mod.rs
+17
-26
resolve.rs
crates/next-core/src/next_shared/resolve.rs
+13
-21
Cargo.toml
turbopack/crates/turbopack-image/Cargo.toml
+1
-1
svg.rs
turbopack/crates/turbopack-image/src/process/svg.rs
+13
-15
No files found.
Cargo.lock
View file @
26afa892
...
...
@@ -4829,6 +4829,7 @@ dependencies = [
"next-custom-transforms",
"next-taskless",
"percent-encoding",
"phf",
"qstring",
"react_remove_properties",
"regex",
...
...
@@ -10496,8 +10497,8 @@ dependencies = [
"bincode 2.0.1",
"image",
"mime",
"phf",
"regex",
"rustc-hash 2.1.1",
"serde",
"turbo-bincode",
"turbo-rcstr",
...
...
crates/next-core/Cargo.toml
View file @
26afa892
...
...
@@ -25,6 +25,7 @@ itertools = { workspace = true }
lightningcss
=
{
workspace
=
true
}
mime_guess
=
"2.0.4"
percent-encoding
=
"2.3.1"
phf
=
{
workspace
=
true
}
qstring
=
{
workspace
=
true
}
react_remove_properties
=
{
workspace
=
true
}
regex
=
{
workspace
=
true
}
...
...
crates/next-core/src/next_app/metadata/mod.rs
View file @
26afa892
use
std
::
{
ops
::
Deref
,
sync
::
LazyLock
}
;
use
std
::
sync
::
LazyLock
;
use
anyhow
::
Result
;
use
phf
::
phf_map
;
use
regex
::
Regex
;
use
rustc_hash
::
FxHashMap
;
use
turbo_rcstr
::
RcStr
;
use
turbo_tasks_fs
::
FileSystemPath
;
...
...
@@ -11,28 +11,19 @@ use crate::next_app::{AppPage, AppPath, PageSegment, PageType};
pub
mod
image
;
pub
mod
route
;
pub
static
STATIC_LOCAL_METADATA
:
LazyLock
<
FxHashMap
<&
'static
str
,
&
'static
[
&
'static
str
]
>>
=
LazyLock
::
new
(||
{
FxHashMap
::
from_iter
([
(
"icon"
,
&
[
"ico"
,
"jpg"
,
"jpeg"
,
"png"
,
"svg"
]
as
&
'static
[
&
'static
str
],
),
(
"apple-icon"
,
&
[
"jpg"
,
"jpeg"
,
"png"
]),
(
"opengraph-image"
,
&
[
"jpg"
,
"jpeg"
,
"png"
,
"gif"
]),
(
"twitter-image"
,
&
[
"jpg"
,
"jpeg"
,
"png"
,
"gif"
]),
(
"sitemap"
,
&
[
"xml"
]),
])
});
pub
static
STATIC_LOCAL_METADATA
:
phf
::
Map
<&
'static
str
,
&
'static
[
&
'static
str
]
>
=
phf_map!
{
"icon"
=>
&
[
"ico"
,
"jpg"
,
"jpeg"
,
"png"
,
"svg"
],
"apple-icon"
=>
&
[
"jpg"
,
"jpeg"
,
"png"
],
"opengraph-image"
=>
&
[
"jpg"
,
"jpeg"
,
"png"
,
"gif"
],
"twitter-image"
=>
&
[
"jpg"
,
"jpeg"
,
"png"
,
"gif"
],
"sitemap"
=>
&
[
"xml"
],
};
pub
static
STATIC_GLOBAL_METADATA
:
LazyLock
<
FxHashMap
<&
'static
str
,
&
'static
[
&
'static
str
]
>>
=
LazyLock
::
new
(||
{
FxHashMap
::
from_iter
([
(
"favicon"
,
&
[
"ico"
]
as
&
'static
[
&
'static
str
]),
(
"manifest"
,
&
[
"webmanifest"
,
"json"
]),
(
"robots"
,
&
[
"txt"
]),
])
});
pub
static
STATIC_GLOBAL_METADATA
:
phf
::
Map
<&
'static
str
,
&
'static
[
&
'static
str
]
>
=
phf_map!
{
"favicon"
=>
&
[
"ico"
],
"manifest"
=>
&
[
"webmanifest"
,
"json"
],
"robots"
=>
&
[
"txt"
],
};
pub
struct
MetadataFileMatch
<
'a
>
{
pub
metadata_type
:
&
'a
str
,
...
...
@@ -56,7 +47,7 @@ fn match_numbered_metadata(stem: &str) -> Option<(&str, &str)> {
fn
match_metadata_file
<
'a
>
(
filename
:
&
'a
str
,
page_extensions
:
&
[
RcStr
],
metadata
:
&
FxHashMap
<&
str
,
&
[
&
str
]
>
,
metadata
:
&
phf
::
Map
<&
'static
str
,
&
'static
[
&
'static
str
]
>
,
)
->
Option
<
MetadataFileMatch
<
'a
>>
{
let
(
stem
,
ext
)
=
filename
.split_once
(
'.'
)
?
;
...
...
@@ -123,7 +114,7 @@ pub fn match_local_metadata_file<'a>(
basename
:
&
'a
str
,
page_extensions
:
&
[
RcStr
],
)
->
Option
<
MetadataFileMatch
<
'a
>>
{
match_metadata_file
(
basename
,
page_extensions
,
STATIC_LOCAL_METADATA
.deref
()
)
match_metadata_file
(
basename
,
page_extensions
,
&
STATIC_LOCAL_METADATA
)
}
pub
struct
GlobalMetadataFileMatch
<
'a
>
{
...
...
@@ -135,7 +126,7 @@ pub fn match_global_metadata_file<'a>(
basename
:
&
'a
str
,
page_extensions
:
&
[
RcStr
],
)
->
Option
<
GlobalMetadataFileMatch
<
'a
>>
{
match_metadata_file
(
basename
,
page_extensions
,
STATIC_GLOBAL_METADATA
.deref
()
)
.map
(|
m
|
{
match_metadata_file
(
basename
,
page_extensions
,
&
STATIC_GLOBAL_METADATA
)
.map
(|
m
|
{
GlobalMetadataFileMatch
{
metadata_type
:
m
.metadata_type
,
dynamic
:
m
.dynamic
,
...
...
crates/next-core/src/next_shared/resolve.rs
View file @
26afa892
use
std
::
sync
::
LazyLock
;
use
anyhow
::
Result
;
use
async_trait
::
async_trait
;
use
rustc_hash
::
FxHashM
ap
;
use
phf
::
phf_m
ap
;
use
turbo_rcstr
::{
RcStr
,
rcstr
};
use
turbo_tasks
::{
ResolvedVc
,
Vc
};
use
turbo_tasks_fs
::{
...
...
@@ -29,24 +27,18 @@ use crate::{next_server::ServerContextType, next_telemetry::ModuleFeatureTelemet
// Set of the features we want to track, following existing references in
// webpack/plugins/telemetry-plugin.
static
FEATURE_MODULES
:
LazyLock
<
FxHashMap
<&
'static
str
,
Vec
<&
'static
str
>>>
=
LazyLock
::
new
(||
{
FxHashMap
::
from_iter
([
(
"next"
,
vec!
[
"/image"
,
"/future/image"
,
"/legacy/image"
,
"/script"
,
"/dynamic"
,
"/font/google"
,
"/font/local"
,
],
),
(
"@next/font"
,
vec!
[
"/google"
,
"/local"
]),
])
});
static
FEATURE_MODULES
:
phf
::
Map
<&
'static
str
,
&
'static
[
&
'static
str
]
>
=
phf_map!
{
"next"
=>
&
[
"/image"
,
"/future/image"
,
"/legacy/image"
,
"/script"
,
"/dynamic"
,
"/font/google"
,
"/font/local"
,
],
"@next/font"
=>
&
[
"/google"
,
"/local"
],
};
#[turbo_tasks
::
value(shared)]
pub
struct
InvalidImportModuleIssue
{
...
...
turbopack/crates/turbopack-image/Cargo.toml
View file @
26afa892
...
...
@@ -32,8 +32,8 @@ image = { workspace = true, default-features = false, features = [
"tga"
,
]
}
mime
=
{
workspace
=
true
}
phf
=
{
workspace
=
true
}
regex
=
{
workspace
=
true
}
rustc-hash
=
{
workspace
=
true
}
serde
=
{
workspace
=
true
}
turbo-bincode
=
{
workspace
=
true
}
turbo-rcstr
=
{
workspace
=
true
}
...
...
turbopack/crates/turbopack-image/src/process/svg.rs
View file @
26afa892
...
...
@@ -4,24 +4,22 @@
use
std
::
sync
::
LazyLock
;
use
anyhow
::{
Result
,
anyhow
,
bail
};
use
phf
::
phf_map
;
use
regex
::
Regex
;
use
rustc_hash
::
FxHashMap
;
const
INCH_CM
:
f64
=
2.54
;
static
UNITS
:
LazyLock
<
FxHashMap
<&
str
,
f64
>>
=
LazyLock
::
new
(||
{
FxHashMap
::
from_iter
([
(
"in"
,
96.0
),
(
"cm"
,
96.0
/
INCH_CM
),
(
"em"
,
16.0
),
(
"ex"
,
8.0
),
(
"m"
,
96.0
/
INCH_CM
*
100.0
),
(
"mm"
,
96.0
/
INCH_CM
/
10.0
),
(
"pc"
,
96.0
/
72.0
/
12.0
),
(
"pt"
,
96.0
/
72.0
),
(
"px"
,
1.0
),
(
""
,
1.0
),
])
});
static
UNITS
:
phf
::
Map
<&
'static
str
,
f64
>
=
phf_map!
{
"in"
=>
96.0
,
"cm"
=>
96.0
/
INCH_CM
,
"em"
=>
16.0
,
"ex"
=>
8.0
,
"m"
=>
96.0
/
INCH_CM
*
100.0
,
"mm"
=>
96.0
/
INCH_CM
/
10.0
,
"pc"
=>
96.0
/
72.0
/
12.0
,
"pt"
=>
96.0
/
72.0
,
"px"
=>
1.0
,
""
=>
1.0
,
};
static
UNIT_REGEX
:
LazyLock
<
Regex
>
=
LazyLock
::
new
(||
{
Regex
::
new
(
r
"^([0-9.]+(?:e-?
\
d+)?)((?:in|cm|em|ex|m|mm|pc|pt|px)?)$"
)
.unwrap
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment