8000 Refactor Search validator to allocation-free implementation. · Issue #424 · ardalis/Specification · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Refactor Search validator to allocation-free implementation. #424
Closed
@fiseni

Description

@fiseni

The current SearchValidator implementation is as follows.

public bool IsValid<T>(T entity, ISpecification<T> specification)
{
    foreach (var searchGroup in specification.SearchCriterias.GroupBy(x => x.SearchGroup))
    {
        if (searchGroup.Any(c => c.SelectorFunc(entity).Like(c.SearchTerm)) == false) return false;
    }

    return true;
}

This looks relatively simple, but there are a lot of hidden allocations. Moreover, the number of allocations is not constant, and it depends on the size of the input collection.

We need allocation-free GroupBy implementation. We may keep the search expressions sorted by search group, and then slice to get the groups.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0