tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

BorderCache.h (1659B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef mozilla_BorderCache_h_
      8 #define mozilla_BorderCache_h_
      9 
     10 #include "PLDHashTable.h"
     11 #include "mozilla/HashFunctions.h"
     12 #include "mozilla/gfx/2D.h"
     13 
     14 namespace mozilla {
     15 // Cache for best overlap and best dashLength.
     16 
     17 struct FourFloats {
     18  typedef mozilla::gfx::Float Float;
     19 
     20  Float n[4];
     21 
     22  FourFloats() {
     23    n[0] = 0.0f;
     24    n[1] = 0.0f;
     25    n[2] = 0.0f;
     26    n[3] = 0.0f;
     27  }
     28 
     29  FourFloats(Float a, Float b, Float c, Float d) {
     30    n[0] = a;
     31    n[1] = b;
     32    n[2] = c;
     33    n[3] = d;
     34  }
     35 
     36  bool operator==(const FourFloats&) const = default;
     37 };
     38 
     39 class FourFloatsHashKey : public PLDHashEntryHdr {
     40 public:
     41  typedef const FourFloats& KeyType;
     42  typedef const FourFloats* KeyTypePointer;
     43 
     44  explicit FourFloatsHashKey(KeyTypePointer aKey) : mValue(*aKey) {}
     45  FourFloatsHashKey(const FourFloatsHashKey& aToCopy)
     46      : mValue(aToCopy.mValue) {}
     47  ~FourFloatsHashKey() = default;
     48 
     49  KeyType GetKey() const { return mValue; }
     50  bool KeyEquals(KeyTypePointer aKey) const { return *aKey == mValue; }
     51 
     52  static KeyTypePointer KeyToPointer(KeyType aKey) { return &aKey; }
     53  static PLDHashNumber HashKey(KeyTypePointer aKey) {
     54    return HashBytes(aKey->n, sizeof(mozilla::gfx::Float) * 4);
     55  }
     56  enum { ALLOW_MEMMOVE = true };
     57 
     58 private:
     59  const FourFloats mValue;
     60 };
     61 
     62 }  // namespace mozilla
     63 
     64 #endif /* mozilla_BorderCache_h_ */