-
Notifications
You must be signed in to change notification settings - Fork 221
perf(network): Improve performance by refactoring loop logic and removing unused static variables #2659
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
perf(network): Improve performance by refactoring loop logic and removing unused static variables #2659
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -341,8 +341,7 @@ void LANAPI::update() | |
| } | ||
|
|
||
| // Handle any new messages | ||
| int i; | ||
| for (i=0; i<MAX_MESSAGES && !LANbuttonPushed; ++i) | ||
| for (size_t i = 0; i < ARRAY_SIZE(m_transport->m_inBuffer) && !LANbuttonPushed; ++i) | ||
| { | ||
| if (m_transport->m_inBuffer[i].length > 0) | ||
| { | ||
|
|
@@ -432,6 +431,10 @@ void LANAPI::update() | |
| // Mark it as read | ||
| m_transport->m_inBuffer[i].length = 0; | ||
| } | ||
| else | ||
| { | ||
| break; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So there cannot be non-zero buffer after a zero buffer, yes?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's right. |
||
| } | ||
| } | ||
| if(LANbuttonPushed) | ||
| return; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -325,7 +325,7 @@ NATConnectionState NAT::connectionUpdate() { | |
| m_transport->update(); | ||
|
|
||
| // check to see if we've been probed. | ||
| for (Int i = 0; i < MAX_MESSAGES; ++i) { | ||
| for (size_t i = 0; i < ARRAY_SIZE(m_transport->m_inBuffer); ++i) { | ||
| if (m_transport->m_inBuffer[i].length > 0) { | ||
| #ifdef DEBUG_LOGGING | ||
| UnsignedInt ip = m_transport->m_inBuffer[i].addr; | ||
|
|
@@ -368,6 +368,8 @@ NATConnectionState NAT::connectionUpdate() { | |
| PRINTF_IP_AS_4_INTS(ip), m_transport->m_inBuffer[i].port)); | ||
| m_transport->m_inBuffer[i].length = 0; | ||
| } | ||
| } else { | ||
| break; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alternatively could do early breaks in the loops. But its ok either way. |
||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Status quo: Compares with
> 0,!= 0Expectation:
> 0,<= 0or
== 0,!= 0There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've split this off to a separate commit. I do think this is the right comparator, though, as long as
lengthis still signed.The original code already does it this way here:
GeneralsGameCode/Core/GameEngine/Source/GameNetwork/LANAPI.cpp
Line 347 in ca9358f
GeneralsGameCode/Core/GameEngine/Source/GameNetwork/NAT.cpp
Line 329 in ca9358f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can change the
== 0cases to<= 0if you like.