Repository: microsoft/garnet
File: libs/server/Custom/ExpandableMap.cs (C#)

Code before:
                {
                    var b1 = cmd[j];
                    var b2 = Name[j];

                    if ((b1 != b2) && ((b2 < 65) || (b2 > 90) || (b1 - 32 != b2)))
                    {
                        return false;
                    }
                }

                return true;
            }

            value = default;

            // Take the current map instance and its size
            // Note: Map instance could be updated as the map expands, but in this context we only care about its current snapshot
            // Map's actual size could only grow, which is why it's important to take the size snapshot before the map itself.
            var mapSize = eMap.ActualSize;
            var map = eMap.Map;

            // Try to match the specified command with the commands in the current map
            for (var i = 0; i < mapSize; i++)
            {
                var currCmd = map[i];
                if (EqualsUpperCaseSpanIgnoringCase(cmd, currCmd?.Name))
                {
                    value = currCmd;
                    return true;
                }
            }

            return false;
        }

        /// <summary>
        /// Match sub-command name with existing sub-commands in map and return first matching instance
        /// </summary>
        /// <typeparam name="T">Type of command</typeparam>
        /// <param name="eMap">Current instance of ExpandableMap</param>
        /// <param name="cmd">Sub-command name to match</param>
        /// <param name="value">Value of sub-command found</param>
        /// <returns></returns>
        internal static bool MatchSubCommand<T>(this ExpandableMap<T> eMap, ReadOnlySpan<byte> cmd, out CustomObjectCommand value)
            where T : CustomObjectCommandWrapper
        {
            value = default;

            // Take the current map instance and its size
            // Note: Map instance could be updated as the map expands, but in this context we only care about its current snapshot
            // Map's actual size could only grow, which is why it's important to take the size snapshot before the map itself.

Review comment (suggestion):
No need to call the method if `currCmd == null`, you can leave that as part of the condition.

Code after:
                    value = currCmd;
                    return true;
                }
            }

            return false;
        }

        /// <summary>
        /// Match sub-command name with existing sub-commands in map and return first matching instance
        /// </summary>
        /// <typeparam name="T">Type of command</typeparam>
        /// <param name="eMap">Current instance of ExpandableMap</param>
        /// <param name="cmd">Sub-command name to match</param>
        /// <param name="value">Value of sub-command found</param>
        /// <returns></returns>
        internal static bool MatchSubCommand<T>(this ExpandableMap<T> eMap, ReadOnlySpan<byte> cmd, out CustomObjectCommand value)
            where T : CustomObjectCommandWrapper
        {
            value = default;

            // Take the current map instance and its size
            // Note: Map instance could be updated as the map expands, but in this context we only care about its current snapshot
            // Map's actual size could only grow, which is why it's important to take the size snapshot before the map itself.
            var mapSize = eMap.ActualSize;
            var map = eMap.Map;

            // Try to match the specified sub-command with each command's sub-command maps
            for (var i = 0; i < mapSize; i++)
            {
                var subCommandEMap = map[i]?.commandMap;
                if (subCommandEMap.HasValue && subCommandEMap.Value.MatchCommand(cmd, out value))
                {
                    return true;
                }
            }

            return false;
        }
    }
}