tor-browser

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

coord-setter.hh (1358B)


      1 #ifndef OT_VAR_VARC_COORD_SETTER_HH
      2 #define OT_VAR_VARC_COORD_SETTER_HH
      3 
      4 
      5 #include "../../../hb.hh"
      6 
      7 
      8 namespace OT {
      9 //namespace Var {
     10 
     11 
     12 struct coord_setter_t
     13 {
     14  coord_setter_t (hb_array_t<const int> coords_)
     15  {
     16    length = coords_.length;
     17    if (length <= ARRAY_LENGTH (static_coords))
     18      hb_memcpy (static_coords, coords_.arrayZ, length * sizeof (int));
     19    else
     20      dynamic_coords.extend (coords_);
     21  }
     22 
     23  int& operator [] (unsigned idx)
     24  {
     25    if (unlikely (idx >= HB_VAR_COMPOSITE_MAX_AXES))
     26      return Crap(int);
     27 
     28    if (length <= ARRAY_LENGTH (static_coords))
     29    {
     30      if (idx < ARRAY_LENGTH (static_coords))
     31      {
     32        while (length <= idx)
     33   static_coords[length++] = 0;
     34 return static_coords[idx];
     35      }
     36      else
     37        dynamic_coords.extend (hb_array (static_coords, length));
     38    }
     39 
     40    if (dynamic_coords.length <= idx)
     41    {
     42      if (unlikely (!dynamic_coords.resize (idx + 1)))
     43 return Crap(int);
     44      length = idx + 1;
     45    }
     46    return dynamic_coords.arrayZ[idx];
     47  }
     48 
     49  hb_array_t<int> get_coords ()
     50  { return length <= ARRAY_LENGTH (static_coords) ? hb_array (static_coords, length) : dynamic_coords.as_array (); }
     51 
     52  private:
     53  hb_vector_t<int> dynamic_coords;
     54  unsigned length;
     55  int static_coords[sizeof (void *) * 8];
     56 };
     57 
     58 
     59 //} // namespace Var
     60 
     61 } // namespace OT
     62 
     63 #endif /* OT_VAR_VARC_COORD_SETTER_HH */