Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/local-gates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ jobs:
scripts/tests/test_check_eol.py scripts/tests/test_normalize_eol.py scripts/tests/test_lint_error_codes.py
scripts/tests/test_code_samples.py
scripts/tests/test_skill_sizes.py scripts/tests/test_comment_block_form.py
scripts/tests/test_doc_links.py
scripts/tests/test_lifecycle_lint.py scripts/tests/test_yaml_lint.py scripts/tests/test_no_regions.py scripts/tests/test_dependabot.py scripts/tests/test_doc_samples.py -q

- name: Verify compiler payload publication on Windows
Expand Down
2 changes: 1 addition & 1 deletion .llm/references/contract-fixture-launch-audit.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ All paths in this table are under `scripts/tests/`. Counts are executable source
| [test-lint-csharp-naming.ps1](../../scripts/tests/test-lint-csharp-naming.ps1) | 1 | CLI: parameterless smoke. Content cases already use runspaces. |
| [test-lint-dependabot.ps1](../../scripts/tests/test-lint-dependabot.ps1) | 2 | CLI: single and multiple `-Paths` binding, including the malformed invocation. Content cases already use runspaces. |
| [test-lint-doc-counts.ps1](../../scripts/tests/test-lint-doc-counts.ps1) | 1 | CLI: wrapper delegates to a native child; exact 0/1/42 status propagation, missing-script termination, and unexpected CLI argument rejection. Keep its five assertions. |
| [test-lint-doc-links.ps1](../../scripts/tests/test-lint-doc-links.ps1) | 1 | CLI: subdirectory invocation, multiple `-Paths`, and `-Mode` binding. Content cases already use runspaces. |
| [test-lint-doc-links.ps1](../../scripts/tests/test-lint-doc-links.ps1) | 1 | Compatibility wrapper over typed Python tests. CLI controls cover foreign working directories, multiple `-Paths`, and all `-Mode` values; 41 captured content cases replay in process. |
| [test-lint-skill-sizes.ps1](../../scripts/tests/test-lint-skill-sizes.ps1) | 1 | CLI: additional-argument branch tests CLI rejection and verbose binding. Content cases already use runspaces. |
| [test-lint-unity-test-modules.ps1](../../scripts/tests/test-lint-unity-test-modules.ps1) | 1 | CLI: real manifest `-Path` binding smoke. Content cases already use runspaces. |
| [test-llm-instructions-lint.ps1](../../scripts/tests/test-llm-instructions-lint.ps1) | 1 | CLI: real linter smoke. Two generator calls now use fresh runspaces; the separate ProcessStartInfo helper preserves real CLI file/stdout bytes and missing-skills failure. |
Expand Down
2 changes: 1 addition & 1 deletion .llm/references/linter-reference-part-3.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Runs these in sequence:

| Helper | Purpose |
| ------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `scripts/comment-stripping.ps1` | Language-aware comment masker used by `lint-doc-links`, `lint-csharp-naming`, `lint-odin-undo-safety`, `lint-drawer-multiobject`. Replaces comment characters with spaces while preserving line/column offsets so downstream regex scans don't false-positive on commented-out code. Public API: `Get-LanguageFromExtension`, `Get-CommentMaskedLines`, `Get-CommentRanges`. Pinned by `scripts/tests/test-comment-stripping.ps1`. |
| `scripts/comment-stripping.ps1` | Language-aware comment masker used by `lint-csharp-naming`, `lint-odin-undo-safety`, `lint-drawer-multiobject`. Replaces comment characters with spaces while preserving line/column offsets so downstream regex scans don't false-positive on commented-out code. Public API: `Get-LanguageFromExtension`, `Get-CommentMaskedLines`, `Get-CommentRanges`. Pinned by `scripts/tests/test-comment-stripping.ps1`. |
| `scripts/git-path-helpers.ps1` | Normalizes filesystem paths to repo-relative POSIX form for safe use with `git check-ignore` and related plumbing. |

For typed Python checks, reuse `scripts/csharp_sources.py` to mask C# literals and comments.
Expand Down
2 changes: 1 addition & 1 deletion .llm/skill-splits.json
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@
},
{
"name": "linter-reference",
"sha256": "6113f6cd4bedf1fa3667c1b2578259c4b4b5437d62d0c8317400dc94c014f242",
"sha256": "eb3dec89af14f2677e2204e0fbf4beb61145454293416d3539e4c2db4408c94f",
"parts": [
"linter-reference-part-1.md",
"linter-reference-part-2.md",
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Add `ThreadAmbient<T>` for per-thread context with nested scopes and safe repeated disposal ([#1175](https://github.com/Ambiguous-Interactive/unity-helpers/issues/1175)).
- Add stable little-endian integer hash steps, raw UTF-16 text hashing, and explicitly weak whole-word FNV folding ([#1174](https://github.com/Ambiguous-Interactive/unity-helpers/issues/1174)).
- Add `HoldSet` for independent input or pause holds, disposable handles, occupancy callbacks, and destroyed-owner cleanup ([#1183](https://github.com/Ambiguous-Interactive/unity-helpers/issues/1183)).
- Add `StopwatchTimestamp` for elapsed time and counter-tick conversions without a timer allocation ([#1179](https://github.com/Ambiguous-Interactive/unity-helpers/issues/1179)).
- Add stable in-place insertion sort for spans without renting a buffer ([#1157](https://github.com/Ambiguous-Interactive/unity-helpers/issues/1157)).
- Add optional struct discovery to `GetTypesDerivedFrom` while retaining the default class-only filter ([#1169](https://github.com/Ambiguous-Interactive/unity-helpers/issues/1169)).
Expand All @@ -33,8 +36,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Compute integer floor logarithms with portable branchless lookups, preserving zero and signed bit-pattern results ([#1170](https://github.com/Ambiguous-Interactive/unity-helpers/issues/1170)).
- Update bundled JSON and immutable collections to 10.0.15 while retaining Unity assembly constraints ([#1052](https://github.com/Ambiguous-Interactive/unity-helpers/issues/1052)).
- Reduce allocations and speed up dense drawn sprite bounds ([#1113](https://github.com/Ambiguous-Interactive/unity-helpers/issues/1113)).
- Reduce repeated pixel reads in sprite ink-region queries, reduce allocations, and speed up dense drawn sprite bounds ([#1113](https://github.com/Ambiguous-Interactive/unity-helpers/issues/1113)).
- Cache general-format enum flag names through the full mask when it fits in 256 slots ([#1168](https://github.com/Ambiguous-Interactive/unity-helpers/issues/1168)).
- Skip unset words when collecting or enumerating sparse `BitSet` indices.
- Reduce repeated script searches during bulk binding validation ([#1106](https://github.com/Ambiguous-Interactive/unity-helpers/issues/1106)).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.11.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.12.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit3TestAdapter" Version="6.3.1" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="5.9.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
Update="Captured/*.cs.txt;Data/*.bin;Data/*.json.txt;DoxRetainedInventory.v1.json"
CopyToOutputDirectory="PreserveNewest"
/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.11.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.12.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit3TestAdapter" Version="6.3.1" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<Compile Include="../../Runtime/Utils/DisposalLease.cs" Link="DisposalLease.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.11.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.12.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit3TestAdapter" Version="6.3.1" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
<Compile Include="../../Tests/Runtime/TestUtils/GCAssert.cs" Link="GCAssert.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.11.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.12.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit3TestAdapter" Version="6.3.1" />
<PackageReference
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<Compile Include="../../Tests/Runtime/TestUtils/GCAssert.cs" Link="GCAssert.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.11.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.12.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit3TestAdapter" Version="6.3.1" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
CopyToOutputDirectory="PreserveNewest"
/>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.8.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.11.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.12.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit3TestAdapter" Version="6.3.1" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@
PrivateAssets="all"
ExcludeAssets="all"
/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.11.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.12.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit3TestAdapter" Version="6.3.1" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="5.9.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
PrivateAssets="all"
GeneratePathProperty="true"
/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.11.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.12.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit3TestAdapter" Version="6.3.1" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
/>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.11.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.12.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit3TestAdapter" Version="6.3.1" />
</ItemGroup>
Expand Down
189 changes: 189 additions & 0 deletions Runtime/Core/DataStructure/HoldSet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
// MIT License - Copyright (c) 2026 wallstop
// Full license text: https://github.com/wallstop/unity-helpers/blob/main/LICENSE

namespace WallstopStudios.UnityHelpers.Core.DataStructure
{
using System;
using System.Collections.Generic;
using UnityEngine;

/// <summary>Counts independent holds and reports transitions between held and released.</summary>
/// <remarks>
/// Use on the Unity main thread. Each acquisition is independent, including repeated owners.
/// Call SweepDestroyedOwners to release destroyed Unity owners; ordinary owners require disposal.
/// Callbacks observe the committed state and may reenter. Callback failures are logged.
/// </remarks>
public sealed class HoldSet : IDisposable
{
/// <summary>Gets the number of outstanding acquisitions, including owners not yet swept.</summary>
public int Count => _owners.Count;

/// <summary>Gets whether at least one acquisition is outstanding.</summary>
public bool IsHeld => _owners.Count != 0;

/// <summary>Gets whether this set has permanently stopped accepting holds.</summary>
public bool IsDisposed => _disposed;

private readonly Dictionary<long, object> _owners = new();
private readonly List<long> _destroyed = new();
private readonly Action _onFirstAcquired;
private readonly Action _onLastReleased;
private long _nextIdentity;
private bool _disposed;

/// <summary>Creates a set with optional callbacks for its two occupancy transitions.</summary>
public HoldSet(Action onFirstAcquired = null, Action onLastReleased = null)
{
_onFirstAcquired = onFirstAcquired;
_onLastReleased = onLastReleased;
}

private static bool InvokeCallback(Action callback)
{
if (callback == null)
{
return true;
}
try
{
callback();
return true;
}
catch (Exception exception)
{
try
{
Debug.LogException(exception);
}
catch (Exception)
{
// Cleanup must not depend on a custom log handler succeeding.
}
return false;
}
}

/// <summary>Acquires an independent hold, or returns an inactive handle for an unavailable owner or set.</summary>
/// <remarks>
/// Null and destroyed Unity owners are refused. Copies of a handle release the same hold once.
/// If the first-acquired callback fails, this acquisition is released and an inactive handle is returned.
/// </remarks>
public Handle Acquire(object owner)
{
if (
_disposed
|| owner == null
|| (owner is UnityEngine.Object unityOwner && unityOwner == null)
|| _nextIdentity == long.MaxValue
)
{
return default;
}

long identity = ++_nextIdentity;
bool wasEmpty = _owners.Count == 0;
_owners.Add(identity, owner);
Handle handle = new(this, identity);
if (wasEmpty && !InvokeCallback(_onFirstAcquired))
{
Release(identity);
return default;
}
return handle;
}

/// <summary>Releases outstanding holds whose Unity owners have been destroyed and returns their count.</summary>
public int SweepDestroyedOwners()
{
_destroyed.Clear();
foreach (KeyValuePair<long, object> entry in _owners)
{
if (entry.Value is UnityEngine.Object owner && owner == null)
{
_destroyed.Add(entry.Key);
}
}
int count = _destroyed.Count;
foreach (long identity in _destroyed)
{
_owners.Remove(identity);
}
_destroyed.Clear();
if (0 < count && _owners.Count == 0)
{
InvokeCallback(_onLastReleased);
}
return count;
}

/// <summary>Releases all current holds while allowing later acquisitions.</summary>
public void Clear()
{
bool wasHeld = _owners.Count != 0;
_owners.Clear();
if (wasHeld)
{
InvokeCallback(_onLastReleased);
}
}

/// <summary>Permanently refuses new holds and releases all outstanding acquisitions once.</summary>
public void Dispose()
{
if (_disposed)
{
return;
}
_disposed = true;
Clear();
}

private void Release(long identity)
{
if (_owners.Remove(identity) && _owners.Count == 0)
{
InvokeCallback(_onLastReleased);
}
}

/// <summary>A copyable handle whose disposal is safe to repeat.</summary>
public readonly struct Handle : IDisposable, IEquatable<Handle>
{
/// <summary>Gets whether this acquisition is still outstanding.</summary>
public bool IsHeld => _set != null && _set._owners.ContainsKey(_identity);

private readonly HoldSet _set;
private readonly long _identity;

internal Handle(HoldSet set, long identity)
{
_set = set;
_identity = identity;
}

/// <summary>Releases this acquisition once, including across copies of this handle.</summary>
public void Dispose()
{
_set?.Release(_identity);
}

/// <inheritdoc />
public bool Equals(Handle other)
{
return ReferenceEquals(_set, other._set) && _identity == other._identity;
}

/// <inheritdoc />
public override bool Equals(object obj)
{
return obj is Handle other && Equals(other);
}

/// <inheritdoc />
public override int GetHashCode()
{
return HashCode.Combine(_set, _identity);
}
}
}
}
11 changes: 11 additions & 0 deletions Runtime/Core/DataStructure/HoldSet.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading