#173 Optimization for GetRegistriesForPattern


This is not the feature request as such but we can do optimization for GetRegistriesForPattern function in RegistryFinder.cpp.

While finding registry keys for given regex pattern the GetRegistriesForPattern search the registry and enumerate a key and tries to match with pattern.
For this, the function recursively call itself with each time appended new key, if key matches with pattern it saved for return.

Some time recursion is unnecessary,
Eg. suppose Pattern is "^S-[-0-9]+\\Identities\\\{[-0-9A-Z]+\}\\Software\\Microsoft\\Outlook\ Express\\5\.0\\Mail$"
on my machine the function first got '.DEFAULT' key, this will not match with given pattern but still function continues and find next child key '.DEFAULT\Control Panel\...'
it unnecessary goes for unfruitfull path.

What we can do is once we got a key check whether it partially match with given pattern. we goes for next recursion only if key partially matched with pattern, otherwise quit immediately, and try for next sibling key. for this we can use pcre's pcre_dfa_exec() function with PCRE_PARTIAL option.


  • Michael Chisholm

    That is an interesting idea. I didn't know pcre could match incrementally. I looked at the docs, and it says the usual pcre_exec() function also supports PCRE_PARTIAL (PCRE_PARTIAL_SOFT).

    So yeah, that might be possible. I suspect it would represent a break from the old inefficient recompile-the-regex-every-time style of the existing API, because I think you'd need to maintain state across the matching increments. Maybe this could be used as an excuse to throw out REGEX.cpp and redo it better... :)

  • Comment has been marked as spam. 

    You can see all pending comments posted by this user  here

    Anonymous - 2013-04-08

    Thanks Chishomi,
    Could you elaborate more I didn't get exactly, but

    I think we need not have to maintain state, we can write a function as follows:
    Algorithm for partial match :
    bool IsPartialMatch(pattern,searchString)
    compile the pattern say 'compiledPattern'
    Now call pcre_dfa_exec() with argument compiledPattern and PCRE_PARTIAL option.
    if return value is PCRE_ERROR_PARTIAL or non- negative value it means matched partially
    otherwise does not match.
    use this function each time we got new registry key in GetRegistriesForPattern()

    Even we can change first parameter to compiled pattern so that we can compile pattern once and use each time for comparing with different string.

    Is this solution correct ??


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks