Skip to content
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

Optimize operations on dictionaries, fix small issue #420

Merged

Commits on Jan 16, 2024

  1. Optimize operations on dictionaries, fix small issue

    Occurrences of `ContainsKey` followed by indexer getter/setter were replaced by `TryGetValue`/`TryAdd`. In both cases they'll have the same effect.
    
    This also fixes a minor issue with `TypeCache` where `typeByFullName` would check for existence of `Type.Name`, but insert `Type.FullName`.
    
    For extra context/explanation behind dictionary operation changes:
    
    `TryAdd`, `Add`, and indexer all use the same method for adding to dictionary (`TryInsert`, using a different `InsertionBehavior`). This also means that all of them do a check if a value exists in the dictionary before adding the value - and this is the only way they differ. When an entry with a given key exists `TryAdd` just returns early, `Add` will throw an exception, and indexer setter will replace it.
    
    As for `TryGetValue` - it just consolidates the `ContainsKey` and indexer getter into a single call, as all 3 methods call `FindEntry`. This will drop the amount of `FindEntry` calls by 1 each time it's used.
    SokyranTheDragon committed Jan 16, 2024
    Configuration menu
    Copy the full SHA
    d760603 View commit details
    Browse the repository at this point in the history