-
Notifications
You must be signed in to change notification settings - Fork 0
V2/vt refl #1
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
V2/vt refl #1
Changes from all commits
33a65e9
c3d8fe2
2082922
62c9fe3
daf1263
9a26c02
fc6f41b
aad5791
224b8bc
186a8bf
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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -20,18 +20,21 @@ namespace OneScript.StandardLibrary.Collections.ValueTable | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| public class ValueTableColumn : AutoContext<ValueTableColumn> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private string _title; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private string _name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private TypeDescription _valueType; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private string _name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private readonly TypeDescription _valueType; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private readonly WeakReference _owner; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private readonly int _id; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public ValueTableColumn(ValueTableColumnCollection owner, int id, string name, string title, TypeDescription type, int width) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private int _indicesCount = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public bool IsIndexable => _indicesCount != 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public void AddToIndex() { _indicesCount++; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public void DeleteFromIndex() { if (_indicesCount != 0) _indicesCount--; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+27
to
+30
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. Asymmetric AddToIndex/DeleteFromIndex can cause index-count drift.
Additionally, the increment and decrement operations are not thread-safe, which could cause race conditions if indexes are modified concurrently. 🔎 Proposed fix: Add symmetry validation and thread safety private int _indicesCount = 0;
+private readonly object _lockObject = new object();
+
public bool IsIndexable => _indicesCount != 0;
-public void AddToIndex() { _indicesCount++; }
-public void DeleteFromIndex() { if (_indicesCount != 0) _indicesCount--; }
+
+public void AddToIndex()
+{
+ lock (_lockObject)
+ {
+ _indicesCount++;
+ }
+}
+
+public void DeleteFromIndex()
+{
+ lock (_lockObject)
+ {
+ if (_indicesCount == 0)
+ throw new InvalidOperationException("Cannot delete from index: no indexes are tracking this column.");
+ _indicesCount--;
+ }
+}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public ValueTableColumn(ValueTableColumnCollection owner, string name, string title, TypeDescription type, int width) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _name = name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _title = title; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _valueType = type ?? new TypeDescription(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Width = width; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _id = id; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _owner = new WeakReference(owner); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -65,7 +68,6 @@ public string Name | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| _title = value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _name = value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// <summary> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.
🧩 Analysis chain
🏁 Script executed:
Repository: Mr-Rm/OneScript
Length of output: 11094
🏁 Script executed:
Repository: Mr-Rm/OneScript
Length of output: 4888
🏁 Script executed:
Repository: Mr-Rm/OneScript
Length of output: 3384
Prevent duplicate fields in the constructor with validation.
The constructor accepts duplicate fields in the
IEnumerable<IValue> fieldsparameter without validation. If the same column appears multiple times,AddToIndex()will be called multiple times, inflating the_indicesCountcounter. WhileCollectionIndexKey.Extract()usesDictionary.TryAdd()to silently ignore duplicate keys (andRemoveField()handles duplicates symmetrically), allowing duplicates creates unnecessary confusion and overhead. Add validation inBuildFieldList()to reject duplicate field names, or add a check in the constructor to throw if duplicates are detected.🤖 Prompt for AI Agents