') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); Remove one loop in `extract_cfg_from_attrs` by GuillaumeGomez · Pull Request #147133 · rust-lang/rust · GitHub
Skip to content

Remove one loop in extract_cfg_from_attrs - #147133

Merged
bors merged 2 commits into
rust-lang:masterfrom
GuillaumeGomez:rm-loop-extract_cfg_from_attrs
Sep 30, 2025
Merged

Remove one loop in extract_cfg_from_attrs#147133
bors merged 2 commits into
rust-lang:masterfrom
GuillaumeGomez:rm-loop-extract_cfg_from_attrs

Conversation

@GuillaumeGomez

Copy link
Copy Markdown
Member

Follow-up of #138907.

r? lolbinarycat

@rustbotrustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Sep 28, 2025
@GuillaumeGomez

Copy link
Copy Markdown
MemberAuthor

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-borsBot added a commit that referenced this pull request Sep 28, 2025
…, r=<try>
Remove one loop in `extract_cfg_from_attrs`
@rustbotrustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Sep 28, 2025

@lolbinarycatlolbinarycat left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code is sound, as Attribute::ident always returns None for Attribute::Parsed, so there is no case where both branches would have run and now only one runs.

one question about a comment, otherwise lgtm.

View changes since this review

Comment threadsrc/librustdoc/clean/types.rs Outdated
@@ -1085,7 +1085,7 @@ pub(crate) fn extract_cfg_from_attrs<'a, I: Iterator<Item = &'a hir::Attribute>
let mut changed_auto_active_status = None;

// First we get all `doc(auto_cfg)` attributes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this comment still make sense?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It didn't make sense even before. I'll just remove it.

@rust-bors

rust-borsBot commented Sep 28, 2025

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 7b3f411 (7b3f4110d6faa0cbf30b4d01ad4d4f43c3b677e1, parent: c8905eaa66e0c35a33626e974b9ce6955c739b5b)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (7b3f411): comparison URL.

Overall result: ❌ regressions - no action needed

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

meanrangecount
Regressions ❌
(primary)
--0
Regressions ❌
(secondary)
0.0%[0.0%, 0.0%]1
Improvements ✅
(primary)
--0
Improvements ✅
(secondary)
--0
All ❌✅ (primary)--0

Max RSS (memory usage)

Results (primary -0.5%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

meanrangecount
Regressions ❌
(primary)
2.7%[2.7%, 2.7%]1
Regressions ❌
(secondary)
--0
Improvements ✅
(primary)
-3.7%[-3.7%, -3.7%]1
Improvements ✅
(secondary)
--0
All ❌✅ (primary)-0.5%[-3.7%, 2.7%]2

Cycles

Results (secondary 2.8%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

meanrangecount
Regressions ❌
(primary)
--0
Regressions ❌
(secondary)
2.8%[2.3%, 3.4%]3
Improvements ✅
(primary)
--0
Improvements ✅
(secondary)
--0
All ❌✅ (primary)--0

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 470.874s -> 471.366s (0.10%)
Artifact size: 387.66 MiB -> 387.66 MiB (0.00%)

@rustbotrustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Sep 29, 2025
@lolbinarycat

Copy link
Copy Markdown
Contributor

huh, looks like the perf is all noise. I almost thought the increase in cache misses could be something real, as it would match my intuition for potential performance downsides of this change, but on further inspection, none of those are for the doc profile, so it seems like they're just random noise.

still, i'd say it's an improvement to code quality

@GuillaumeGomez

Copy link
Copy Markdown
MemberAuthor

@bors r=lolbinarycat rollup

@bors

bors commented Sep 29, 2025

Copy link
Copy Markdown
Collaborator

📌 Commit 2e63708 has been approved by lolbinarycat

It is now in the queue for this repository.

@borsbors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 29, 2025
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Sep 29, 2025
…_from_attrs, r=lolbinarycat
Remove one loop in `extract_cfg_from_attrs`
Follow-up of rust-lang#138907.
r? lolbinarycat
bors added a commit that referenced this pull request Sep 29, 2025
Rollup of 6 pull requests
Successful merges:
- #143613 (Fix backtraces with `-C panic=abort` on linux; emit unwind tables by default)
- #146937 (std: implement `hostname`)
- #147040 (mbe: macro_check: Fix function comments referencing non-existent parameters)
- #147131 (Use MirPatch in simplify_branches.)
- #147133 (Remove one loop in `extract_cfg_from_attrs`)
- #147150 (Emit allocator attributes for allocator shim)
r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit that referenced this pull request Sep 29, 2025
Rollup of 5 pull requests
Successful merges:
- #146937 (std: implement `hostname`)
- #147040 (mbe: macro_check: Fix function comments referencing non-existent parameters)
- #147131 (Use MirPatch in simplify_branches.)
- #147133 (Remove one loop in `extract_cfg_from_attrs`)
- #147150 (Emit allocator attributes for allocator shim)
r? `@ghost`
`@rustbot` modify labels: rollup
@bors
bors merged commit 967e642 into rust-lang:masterSep 30, 2025
10 checks passed
@rustbotrustbot added this to the 1.92.0 milestone Sep 30, 2025
rust-timer added a commit that referenced this pull request Sep 30, 2025
Rollup merge of #147133 - GuillaumeGomez:rm-loop-extract_cfg_from_attrs, r=lolbinarycat
Remove one loop in `extract_cfg_from_attrs`
Follow-up of #138907.
r? lolbinarycat
@GuillaumeGomez
GuillaumeGomez deleted the rm-loop-extract_cfg_from_attrs branch September 30, 2025 08:57
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@GuillaumeGomez@rust-timer@lolbinarycat@bors@rustbot