Skip to content

Inefficient use of a for loop#10576

Merged
DaanHoogland merged 1 commit intoapache:mainfrom
AsharSi:improves-loop
Jul 11, 2025
Merged

Inefficient use of a for loop#10576
DaanHoogland merged 1 commit intoapache:mainfrom
AsharSi:improves-loop

Conversation

@AsharSi
Copy link
Copy Markdown
Contributor

@AsharSi AsharSi commented Mar 16, 2025

Description

This PR improves how HTTP headers are set in the request. Replacing headers.keySet() with headers.entrySet().

This change enhances efficiency by directly accessing both the key and value in a single iteration, rather than fetching the key first and then looking up the value in the map.

Fixes: #10529

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • build/CI
  • test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

  • Ensured that HTTP requests are still correctly setting headers.
  • Verified that functionality remains unchanged with test cases.

How did you try to break this feature and the system with this change?

@boring-cyborg
Copy link
Copy Markdown

boring-cyborg bot commented Mar 16, 2025

Congratulations on your first Pull Request and welcome to the Apache CloudStack community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/cloudstack/blob/main/CONTRIBUTING.md)
Here are some useful points:

Copy link
Copy Markdown
Member

@weizhouapache weizhouapache left a comment

Choose a reason for hiding this comment

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

code lgtm

not tested yet

@weizhouapache
Copy link
Copy Markdown
Member

@blueorangutan package

@blueorangutan
Copy link
Copy Markdown

@weizhouapache a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 17, 2025

Codecov Report

Attention: Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.

Project coverage is 16.26%. Comparing base (9c6f2a9) to head (e709eab).
Report is 260 commits behind head on main.

Files with missing lines Patch % Lines
...direct/download/HttpsDirectTemplateDownloader.java 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##               main   #10576   +/-   ##
=========================================
  Coverage     16.26%   16.26%           
  Complexity    13388    13388           
=========================================
  Files          5674     5674           
  Lines        498929   498929           
  Branches      60338    60338           
=========================================
+ Hits          81154    81158    +4     
+ Misses       408736   408732    -4     
  Partials       9039     9039           
Flag Coverage Δ
uitests 3.99% <ø> (ø)
unittests 17.12% <0.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@blueorangutan
Copy link
Copy Markdown

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ debian ✔️ suse15. SL-JID 12806

@DaanHoogland
Copy link
Copy Markdown
Contributor

@blueorangutan test

@blueorangutan
Copy link
Copy Markdown

@DaanHoogland a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests

@blueorangutan
Copy link
Copy Markdown

[SF] Trillian test result (tid-12782)
Environment: kvm-ol8 (x2), Advanced Networking with Mgmt server ol8
Total time taken: 57709 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr10576-t12782-kvm-ol8.zip
Smoke tests completed. 141 look OK, 0 have errors, 0 did not run
Only failed and skipped tests results shown below:

Test Result Time (s) Test File

Copy link
Copy Markdown
Contributor

@sureshanaparti sureshanaparti left a comment

Choose a reason for hiding this comment

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

clgtm

@sureshanaparti sureshanaparti requested a review from Copilot June 5, 2025 08:13
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR optimizes HTTP header iteration by switching from headers.keySet() to headers.entrySet(), reducing lookups and improving efficiency.

  • Replaces key-based iteration with entry-based iteration in createUriRequest.
  • Ensures headers are set directly from entry key/value pairs.

@sureshanaparti sureshanaparti added this to the 4.21.0 milestone Jun 5, 2025
@sureshanaparti
Copy link
Copy Markdown
Contributor

@blueorangutan package

@blueorangutan
Copy link
Copy Markdown

@sureshanaparti a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan
Copy link
Copy Markdown

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ debian ✔️ suse15. SL-JID 13609

@DaanHoogland
Copy link
Copy Markdown
Contributor

@blueorangutan test

@blueorangutan
Copy link
Copy Markdown

@DaanHoogland a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests

@blueorangutan
Copy link
Copy Markdown

[SF] Trillian test result (tid-13477)
Environment: kvm-ol8 (x2), Advanced Networking with Mgmt server ol8
Total time taken: 57410 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr10576-t13477-kvm-ol8.zip
Smoke tests completed. 141 look OK, 0 have errors, 0 did not run
Only failed and skipped tests results shown below:

Test Result Time (s) Test File

@DaanHoogland DaanHoogland merged commit 51126a7 into apache:main Jul 11, 2025
24 of 25 checks passed
dhslove pushed a commit to ablecloud-team/ablestack-cloud that referenced this pull request Jul 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

Inefficient use of a for loop

6 participants