Use HashMap::find_with_or_insert_with in DocumentHelpers::register_named_element (fixes #3193)