-
Notifications
You must be signed in to change notification settings - Fork 85
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
Replace CheckLane()
with extensions
#1461
base: master
Are you sure you want to change the base?
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 |
---|---|---|
|
@@ -44,15 +44,24 @@ public static ushort GetTailNode(this ref NetSegment netSegment) { | |
} | ||
|
||
/// <summary> | ||
/// Checks if the netSegment is Created, but neither Collapsed nor Deleted. | ||
/// Checks <paramref name="netSegment"/> is <c>Created</c> but not <c>Collapsed|Deleted</c>. | ||
/// </summary> | ||
/// <param name="netSegment">netSegment</param> | ||
/// <returns>True if the netSegment is valid, otherwise false.</returns> | ||
/// <returns>Returns <c>true</c> if valid, otherwise <c>false</c>.</returns> | ||
public static bool IsValid(this ref NetSegment netSegment) => | ||
netSegment.m_flags.CheckFlags( | ||
required: NetSegment.Flags.Created, | ||
forbidden: NetSegment.Flags.Collapsed | NetSegment.Flags.Deleted); | ||
|
||
/// <summary> | ||
/// Checks <paramref name="segmentId"/> is not <c>0</c>, | ||
/// then checks netSegment is <c>Created</c> but not <c>Collapsed|Deleted</c>. | ||
/// </summary> | ||
/// <param name="segmentId">The id of the segment to check.</param> | ||
/// <returns>Returns <c>true</c> if valid, otherwise <c>false</c>.</returns> | ||
public static bool IsValid(this ushort segmentId) | ||
=> (segmentId != 0) && segmentId.ToSegment().IsValid(); | ||
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. checking segmentId != 0 is redundant because m_segments[0] holds the default value and therefore is not valid. 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. I think we should just use the old extension. 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. If we're sure lane / segment zero will never have @krzychu124 thoughts on this? 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. First element is always thrown away on load so it should have flag 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 it should be ok to ditch the 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. I would check where CO is checking for 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.
If that is the case then we should always check for id != 0. 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. I've realised there are some other issues with this PR, notably that an If we need to check 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 was what I was afraid of (I should have communicated that better). I thin we should minimize the use of 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. One thing I was thinking to include internal static bool IsValidLane(this uint laneId)
=> laneId != 0 && laneId.ToLane().IsValid();
// call site example:
if (!someLaneId.IsValidLane())
return; |
||
|
||
public static NetInfo.Lane GetLaneInfo(this ref NetSegment netSegment, int laneIndex) => | ||
netSegment.Info?.m_lanes?[laneIndex]; | ||
|
||
|
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.
we already have this in lane extensions:
~~But it does not check for laneId < 0
there is the minor issue that we some times check for laneId < 0 and sometimes don't based on the mood of the programmer at the time!~~
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.
wait
uint
cannot be less than zero anyway so its fine.I think we should use the old overload instead of introducing this new one.
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.
Yeah, I know unsigned numbers can't be negative (no idea why so much old code has the
<=
check onushort
anduint
).But regardless, that's not why we check
id != 0
, is it?