Improve use of NeverDestroyed
[WebKit-https.git] / Source / WebCore / xml / XPathParser.cpp
index b6bb205..f3d4b22 100644 (file)
@@ -79,7 +79,7 @@ static XMLCat charCat(UChar character)
     return NotPartOfName;
 }
 
-static void populateAxisNamesMap(HashMap<String, Step::Axis>& axisNames)
+static HashMap<String, Step::Axis> createAxisNamesMap()
 {
     struct AxisName {
         const char* name;
@@ -100,16 +100,15 @@ static void populateAxisNamesMap(HashMap<String, Step::Axis>& axisNames)
         { "preceding-sibling", Step::PrecedingSiblingAxis },
         { "self", Step::SelfAxis }
     };
+    HashMap<String, Step::Axis> map;
     for (auto& axisName : axisNameList)
-        axisNames.add(axisName.name, axisName.axis);
+        map.add(axisName.name, axisName.axis);
+    return map;
 }
 
 static bool parseAxisName(const String& name, Step::Axis& type)
 {
-    static NeverDestroyed<HashMap<String, Step::Axis>> axisNames;
-    if (axisNames.get().isEmpty())
-        populateAxisNamesMap(axisNames);
-
+    static const auto axisNames = makeNeverDestroyed(createAxisNamesMap());
     auto it = axisNames.get().find(name);
     if (it == axisNames.get().end())
         return false;