-
Notifications
You must be signed in to change notification settings - Fork 357
Fix 'isof' and 'cast' unquoted type params issue #3117
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
Merged
Merged
Changes from 30 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
8acf405
Refactor
WanjohiSammy 065d26c
Remove unnecessary changes
WanjohiSammy 425b42c
Remove unnecessary whitespaces
WanjohiSammy 082a1ed
Remove whitespaces
WanjohiSammy 6162161
Remove unnecessary whitespaces
WanjohiSammy b267f82
Remove the private method and just pass the functionName as parameter
WanjohiSammy 421cbbf
Merge branch 'main' into fix/impossible-cast-with-isof-exception
WanjohiSammy 0d37d6c
nit
WanjohiSammy 41a440f
Merge branch 'fix/impossible-cast-with-isof-exception' of https://git…
WanjohiSammy 3e33ff6
Refactor
WanjohiSammy f431035
Remove unnecessary changes
WanjohiSammy c69fd1c
Remove unnecessary whitespaces
WanjohiSammy 7cf4fa7
Remove whitespaces
WanjohiSammy 53e2015
Remove unnecessary whitespaces
WanjohiSammy 6bdf585
Remove the private method and just pass the functionName as parameter
WanjohiSammy 049fae6
nit
WanjohiSammy 0679cdf
Update src/Microsoft.OData.Core/UriParser/Parsers/FunctionCallParser.cs
WanjohiSammy 5f1c503
refactor and merge with origin main
WanjohiSammy 51b1da4
Merge remote-tracking branch 'origin' into fix/impossible-cast-with-i…
WanjohiSammy 7b2a775
Use of NormalizedModelElementsCache
WanjohiSammy c5ba104
using index
WanjohiSammy 7ebd963
nit
WanjohiSammy d7e5211
using SchemaElements
WanjohiSammy 8644a6e
rename tests correctly
WanjohiSammy 04f2f61
Add NormalizedModelElementsCache singleton for EdmCoreModel and use i…
WanjohiSammy 1b7e1c6
FindSchemaTypes can return null
WanjohiSammy f219ef3
Use a lightweight stack struct
WanjohiSammy 106199f
Make StackStruct internal to avoid exposing it to the Public API
WanjohiSammy 76e644d
move StackStructOfT to Microsoft.OData namespace
WanjohiSammy a6e59a8
use explicit types
WanjohiSammy a8d7bce
Update src/Microsoft.OData.Core/UriParser/Resolver/NormalizedModelEle…
WanjohiSammy 785ac02
Use regular Stack
WanjohiSammy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,175 @@ | ||
| //--------------------------------------------------------------------- | ||
| // <copyright file="StackStructOfT.cs" company="Microsoft"> | ||
| // Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. | ||
| // </copyright> | ||
| //--------------------------------------------------------------------- | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using Microsoft.OData.Core; | ||
|
|
||
| namespace Microsoft.OData; | ||
|
|
||
| /// <summary> | ||
| /// A lightweight, struct-based generic stack implementation for value and reference types. | ||
| /// Provides efficient push, pop, and peek operations with dynamic resizing. | ||
| /// </summary> | ||
| /// <typeparam name="T">The type of elements in the stack.</typeparam> | ||
| internal struct StackStruct<T> | ||
| { | ||
| private T[] _items; | ||
| private int _count; | ||
| private const int DefaultCapacity = 4; | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="StackStruct{T}"/> struct with the default capacity. | ||
| /// </summary> | ||
| public StackStruct() | ||
| { | ||
| _items = new T[DefaultCapacity]; | ||
| _count = 0; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="StackStruct{T}"/> struct with the specified capacity. | ||
| /// </summary> | ||
| /// <param name="capacity">The initial number of elements the stack can contain.</param> | ||
| public StackStruct(int capacity) | ||
| { | ||
| _items = new T[capacity]; | ||
| _count = 0; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Pushes an item onto the top of the stack. | ||
| /// </summary> | ||
| /// <param name="item">The item to push onto the stack.</param> | ||
| public void Push(T item) | ||
| { | ||
| EnsureCapacity(); | ||
| _items[_count++] = item; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Removes and returns the item at the top of the stack. | ||
| /// </summary> | ||
| /// <returns>The item removed from the top of the stack.</returns> | ||
| /// <exception cref="InvalidOperationException">Thrown if the stack is empty.</exception> | ||
| public T Pop() | ||
| { | ||
| ThrowIfNullOrEmpty(); | ||
| return _items[--_count]; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Returns the item at the top of the stack without removing it. | ||
| /// </summary> | ||
| /// <returns>The item at the top of the stack.</returns> | ||
| /// <exception cref="InvalidOperationException">Thrown if the stack is empty.</exception> | ||
| public T Peek() | ||
| { | ||
| ThrowIfNullOrEmpty(); | ||
| return _items[_count - 1]; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets a value indicating whether the stack is empty. | ||
| /// </summary> | ||
| public bool IsEmpty => _count == 0; | ||
|
|
||
| /// <summary> | ||
| /// Gets the number of elements contained in the stack. | ||
| /// </summary> | ||
| public int Count => _count; | ||
|
|
||
| /// <summary> | ||
| /// Determines whether the current stack is equal to another object. | ||
| /// </summary> | ||
| /// <param name="obj">The object to compare with the current stack.</param> | ||
| /// <returns>true if the specified object is a <see cref="StackStruct{T}"/> and is equal to the current stack; otherwise, false.</returns> | ||
| public override bool Equals(object obj) | ||
| { | ||
| if (obj is not StackStruct<T> other) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| return Equals(other); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Determines whether the current stack is equal to another <see cref="StackStruct{T}"/>. | ||
| /// Two stacks are equal if they have the same count and all elements are equal in order. | ||
| /// </summary> | ||
| /// <param name="other">The stack to compare with the current stack.</param> | ||
| /// <returns>true if the stacks are equal; otherwise, false.</returns> | ||
| public readonly bool Equals(StackStruct<T> other) | ||
WanjohiSammy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| if (_count != other._count) | ||
| return false; | ||
|
|
||
| EqualityComparer<T> comparer = EqualityComparer<T>.Default; | ||
| for (int i = 0; i < _count; i++) | ||
| { | ||
| if (!comparer.Equals(_items[i], other._items[i])) | ||
| { | ||
| return false; | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Returns a hash code for the current stack. | ||
| /// </summary> | ||
| /// <returns>A hash code for the current stack.</returns> | ||
| public override int GetHashCode() | ||
| { | ||
| EqualityComparer<T> comparer = EqualityComparer<T>.Default; | ||
| int hash = 17; | ||
| hash = hash * 31 + _count.GetHashCode(); | ||
| for (int i = 0; i < _count; i++) | ||
| { | ||
| hash = hash * 31 + comparer.GetHashCode(_items[i]); | ||
| } | ||
| return hash; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Determines whether two <see cref="StackStruct{T}"/> instances are equal. | ||
| /// </summary> | ||
| /// <param name="left">The first stack to compare.</param> | ||
| /// <param name="right">The second stack to compare.</param> | ||
| /// <returns>true if the stacks are equal; otherwise, false.</returns> | ||
| public static bool operator ==(StackStruct<T> left, StackStruct<T> right) | ||
| { | ||
| return left.Equals(right); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Determines whether two <see cref="StackStruct{T}"/> instances are not equal. | ||
| /// </summary> | ||
| /// <param name="left">The first stack to compare.</param> | ||
| /// <param name="right">The second stack to compare.</param> | ||
| /// <returns>true if the stacks are not equal; otherwise, false.</returns> | ||
| public static bool operator !=(StackStruct<T> left, StackStruct<T> right) | ||
| { | ||
| return !(left == right); | ||
| } | ||
|
|
||
| private void EnsureCapacity() | ||
| { | ||
| if (_count == _items.Length) | ||
| { | ||
| Array.Resize(ref _items, _items.Length * 2); | ||
| } | ||
| } | ||
|
|
||
| private readonly void ThrowIfNullOrEmpty() | ||
| { | ||
| if (_count == 0) | ||
| { | ||
| throw new InvalidOperationException(Error.Format(SRResources.ExceptionUtils_IsNullOrEmpty, "StackStruct")); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
This is only light-weight in the wrapper
StackStructis a struct and not an object. So it may save one allocation, but you still use a heap allocated array even for the base case. So It's not really much different from a regularStackand I don't think it's worth creating a custom type.This is different from the version I proposed which would use an inline array buffer (e.g. using
InlineArrayattribute, could usefixedarray buffer, but the latter isunsafeand limited to simple primitive types).But I wouldn't want to block this PR because of this. My suggestion would be to remove this altogether (since it doesn't provide much optimization over a standard Stack, then we can think of a lightweight stack helper in a separate PR that can be used across the codebase)
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.
@habbes I have reverted to use the regular
stack