def get_hook_map(extensions, hook_classes):
    """Create a map of hook classes to extensions that subclass them.
    This is a speedup to avoid having to do `isinstance` checks
    on extensions for every hook invocation.
    """
    hook_map = {}
    for cls in hook_classes:
        hook_map[cls] = [e.obj for e in extensions if isinstance(e.obj, cls)]
    return hook_map