ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libptytty/src/estl.h
(Generate patch)

Comparing libptytty/src/estl.h (file contents):
Revision 1.15 by root, Sat May 19 02:15:31 2012 UTC vs.
Revision 1.19 by sf-exg, Thu May 24 11:48:18 2012 UTC

63 63
64 // we shamelessly optimise for "simple" types. everything 64 // we shamelessly optimise for "simple" types. everything
65 // "not simple enough" will use the slow path. 65 // "not simple enough" will use the slow path.
66 static bool is_simple_enough () 66 static bool is_simple_enough ()
67 { 67 {
68 return 1; // we are not there yet
69 #if __cplusplus >= 201103L 68 #if __cplusplus >= 201103L
70 return std::is_trivially_assignable<T, T>::value 69 return std::is_trivially_assignable<T, T>::value
71 && std::is_trivially_constructable<T>::value 70 && std::is_trivially_constructable<T>::value
72 && std::is_trivially_copyable<T>::value 71 && std::is_trivially_copyable<T>::value
73 && std::is_trivially_destructible<T>::value; 72 && std::is_trivially_destructible<T>::value;
83 82
84 static void construct (iterator a, size_type n = 1) 83 static void construct (iterator a, size_type n = 1)
85 { 84 {
86 if (!is_simple_enough ()) 85 if (!is_simple_enough ())
87 while (n--) 86 while (n--)
88 new (*a++) T (); 87 new (a++) T ();
89 } 88 }
90 89
91 static void destruct (iterator a, size_type n = 1) 90 static void destruct (iterator a, size_type n = 1)
92 { 91 {
93 if (!is_simple_enough ()) 92 if (!is_simple_enough ())
153 iterator src = buf + pos; 152 iterator src = buf + pos;
154 if (is_simple_enough ()) 153 if (is_simple_enough ())
155 memmove (src + n, src, sizeof (T) * n); 154 memmove (src + n, src, sizeof (T) * n);
156 else 155 else
157 for (size_type i = n; i--; ) 156 for (size_type i = n; i--; )
158 op (src + n + i, src + i); 157 cop_set (src + n + i, src + i);
159 } 158 }
160 159
161public: 160public:
162 size_type capacity () const { return res; } 161 size_type capacity () const { return res; }
163 size_type size () const { return sze; } 162 size_type size () const { return sze; }
319 *i++ = t; 318 *i++ = t;
320 319
321 return buf + at; 320 return buf + at;
322 } 321 }
323 322
324 void erase (iterator first, iterator last) 323 iterator erase (iterator first, iterator last)
325 { 324 {
326 size_t n = last - first; 325 size_t n = last - first;
327 326
328 if (is_simple_enough ()) 327 if (is_simple_enough ())
329 memmove (first, last, sizeof (T) * n); 328 memmove (first, last, sizeof (T) * n);
330 else 329 else
331 copy<iterator> (first, last, n, cop_new); 330 copy<iterator> (first, last, n, cop_set);
332 331
333 sze -= n; 332 sze -= n;
334 destruct (buf + sze, n); 333 destruct (buf + sze, n);
335 }
336 334
335 return first;
336 }
337
337 void erase (iterator pos) 338 iterator erase (iterator pos)
338 { 339 {
339 if (pos != end ()) 340 if (pos != end ())
340 erase (pos, pos + 1); 341 erase (pos, pos + 1);
342
343 return pos;
341 } 344 }
342}; 345};
343 346
344template<class T> 347template<class T>
345bool operator ==(const simplevec<T> &v1, const simplevec<T> &v2) 348bool operator ==(const simplevec<T> &v1, const simplevec<T> &v2)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines