ソースを参照

AK: Add StringView::hash()

This grabs the hash from the underlying StringImpl if there is one,
otherwise it's computed on the fly.
Andreas Kling 6 年 前
コミット
d38bd3935b
2 ファイル変更11 行追加0 行削除
  1. 9 0
      AK/StringView.cpp
  2. 2 0
      AK/StringView.h

+ 9 - 0
AK/StringView.cpp

@@ -109,4 +109,13 @@ unsigned StringView::to_uint(bool& ok) const
     return value;
 }
 
+unsigned StringView::hash() const
+{
+    if (is_empty())
+        return 0;
+    if (m_impl)
+        return m_impl->hash();
+    return string_hash(characters_without_null_termination(), length());
+}
+
 }

+ 2 - 0
AK/StringView.h

@@ -39,6 +39,8 @@ public:
     int length() const { return m_length; }
     char operator[](int index) const { return m_characters[index]; }
 
+    unsigned hash() const;
+
     StringView substring_view(int start, int length) const;
     Vector<StringView> split_view(char) const;