Skip to content

.Find() for special lists - #2708

Open
ZeWaka wants to merge 2 commits into
OpenDreamProject:masterfrom
ZeWaka:zw/2302-fix-special-iter
Open

ZeWaka wants to merge 2 commits into
OpenDreamProject:masterfrom
ZeWaka:zw/2302-fix-special-iter

Conversation

@ZeWaka

@ZeWaka ZeWaka commented Sep 11, 2026

Copy link
Copy Markdown
Collaborator

also implemented DreamGlobalVars.GetLength() since my enumeration stuff needs it and it was missing

tested pretty thoroughly in the DM tests, only ones not covered are the 3 client ones (verbs, screen, images)

fixes #2302

@boring-cyborg boring-cyborg Bot added Compiler Involves the OpenDream compiler Runtime Involves the OpenDream server/runtime labels Sep 11, 2026
}

/// <returns>The 1-indexed position of the value, or 0 if it isn't in the [start, end) range</returns>
protected static int FindValueInSpan<T>(ReadOnlySpan<T> values, T value, int start, int end) where T : IEquatable<T> {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

only used a handful of times but figured it was best to abstract this out


/// <summary>
/// Turns Find()'s Start/End into a [start, end) range of 1-indexed positions.
/// End 0 is just past the last element, Start 0 is 1, a negative Start finds nothing.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

unsure if negative start should also be a ListFindOutOfBoundsException

if (!value.TryGetValueAsDreamObject<DreamObjectAtom>(out var atom))
return 0;

return _visContents.IndexOf(atom, start - 1, end - start) + 1;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

indexof is 0-indexed

@ZeWaka
ZeWaka marked this pull request as ready for review September 11, 2026 06:38
Comment thread OpenDreamRuntime/Objects/Types/DreamList.cs
Comment thread OpenDreamRuntime/Objects/Types/DreamList.cs
Comment thread OpenDreamRuntime/Objects/Types/DreamList.cs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Compiler Involves the OpenDream compiler Runtime Involves the OpenDream server/runtime size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.Find() is not implemented on most special list types

2 participants