repeated_ptr_field.h
Go to the documentation of this file.
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following disclaimer
13 // in the documentation and/or other materials provided with the
14 // distribution.
15 // * Neither the name of Google Inc. nor the names of its
16 // contributors may be used to endorse or promote products derived from
17 // this software without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 // Author: kenton@google.com (Kenton Varda)
32 // Based on original Protocol Buffers design by
33 // Sanjay Ghemawat, Jeff Dean, and others.
34 //
35 // RepeatedField and RepeatedPtrField are used by generated protocol message
36 // classes to manipulate repeated fields. These classes are very similar to
37 // STL's vector, but include a number of optimizations found to be useful
38 // specifically in the case of Protocol Buffers. RepeatedPtrField is
39 // particularly different from STL vector as it manages ownership of the
40 // pointers that it contains.
41 //
42 // Typically, clients should not need to access RepeatedField objects directly,
43 // but should instead use the accessor functions generated automatically by the
44 // protocol compiler.
45 //
46 // This header covers RepeatedPtrField.
47 
48 #ifndef GOOGLE_PROTOBUF_REPEATED_PTR_FIELD_H__
49 #define GOOGLE_PROTOBUF_REPEATED_PTR_FIELD_H__
50 
51 #include <utility>
52 #ifdef _MSC_VER
53 // This is required for min/max on VS2013 only.
54 #include <algorithm>
55 #endif
56 
57 #include <iterator>
58 #include <limits>
59 #include <string>
60 #include <type_traits>
61 
62 #include <google/protobuf/stubs/logging.h>
63 #include <google/protobuf/stubs/common.h>
64 #include <google/protobuf/arena.h>
65 #include <google/protobuf/message_lite.h>
66 #include <google/protobuf/port.h>
67 
68 
69 // Must be included last.
70 #include <google/protobuf/port_def.inc>
71 
72 #ifdef SWIG
73 #error "You cannot SWIG proto headers"
74 #endif
75 
76 namespace google {
77 namespace protobuf {
78 
79 class Message;
80 class Reflection;
81 
82 template <typename T>
83 struct WeakRepeatedPtrField;
84 
85 namespace internal {
86 
87 class MergePartialFromCodedStreamHelper;
88 class SwapFieldHelper;
89 
90 
91 } // namespace internal
92 
93 namespace internal {
94 template <typename It>
95 class RepeatedPtrIterator;
96 template <typename It, typename VoidPtr>
97 class RepeatedPtrOverPtrsIterator;
98 } // namespace internal
99 
100 namespace internal {
101 
102 // type-traits helper for RepeatedPtrFieldBase: we only want to invoke
103 // arena-related "copy if on different arena" behavior if the necessary methods
104 // exist on the contained type. In particular, we rely on MergeFrom() existing
105 // as a general proxy for the fact that a copy will work, and we also provide a
106 // specific override for std::string*.
107 template <typename T>
108 struct TypeImplementsMergeBehaviorProbeForMergeFrom {
109  typedef char HasMerge;
110  typedef long HasNoMerge;
111 
112  // We accept either of:
113  // - void MergeFrom(const T& other)
114  // - bool MergeFrom(const T& other)
115  //
116  // We mangle these names a bit to avoid compatibility issues in 'unclean'
117  // include environments that may have, e.g., "#define test ..." (yes, this
118  // exists).
119  template <typename U, typename RetType, RetType (U::*)(const U& arg)>
120  struct CheckType;
121  template <typename U>
123  template <typename U>
125  template <typename U>
126  static HasNoMerge Check(...);
127 
128  // Resolves to either std::true_type or std::false_type.
129  typedef std::integral_constant<bool,
130  (sizeof(Check<T>(0)) == sizeof(HasMerge))>
132 };
133 
134 template <typename T, typename = void>
137 
138 
139 template <>
140 struct TypeImplementsMergeBehavior<std::string> {
142 };
143 
144 template <typename T>
145 struct IsMovable
146  : std::integral_constant<bool, std::is_move_constructible<T>::value &&
147  std::is_move_assignable<T>::value> {};
148 
149 // This is the common base class for RepeatedPtrFields. It deals only in void*
150 // pointers. Users should not use this interface directly.
151 //
152 // The methods of this interface correspond to the methods of RepeatedPtrField,
153 // but may have a template argument called TypeHandler. Its signature is:
154 // class TypeHandler {
155 // public:
156 // typedef MyType Type;
157 // static Type* New();
158 // static Type* NewFromPrototype(const Type* prototype,
159 // Arena* arena);
160 // static void Delete(Type*);
161 // static void Clear(Type*);
162 // static void Merge(const Type& from, Type* to);
163 //
164 // // Only needs to be implemented if SpaceUsedExcludingSelf() is called.
165 // static int SpaceUsedLong(const Type&);
166 // };
167 class PROTOBUF_EXPORT RepeatedPtrFieldBase {
168  protected:
169  constexpr RepeatedPtrFieldBase();
170  explicit RepeatedPtrFieldBase(Arena* arena);
172 #ifndef NDEBUG
173  // Try to trigger segfault / asan failure in non-opt builds. If arena_
174  // lifetime has ended before the destructor.
175  if (arena_) (void)arena_->SpaceAllocated();
176 #endif
177  }
178 
179  // Must be called from destructor.
180  template <typename TypeHandler>
181  void Destroy();
182  bool NeedsDestroy() const { return rep_ != nullptr && arena_ == nullptr; }
183  void DestroyProtos();
184 
185  bool empty() const;
186  int size() const;
187 
188  template <typename TypeHandler>
189  const typename TypeHandler::Type& at(int index) const;
190  template <typename TypeHandler>
191  typename TypeHandler::Type& at(int index);
192 
193  template <typename TypeHandler>
194  typename TypeHandler::Type* Mutable(int index);
195  template <typename TypeHandler>
196  void Delete(int index);
197  template <typename TypeHandler>
198  typename TypeHandler::Type* Add(
199  typename TypeHandler::Type* prototype = nullptr);
200 
201  public:
202  // The next few methods are public so that they can be called from generated
203  // code when implicit weak fields are used, but they should never be called by
204  // application code.
205 
206  template <typename TypeHandler>
207  const typename TypeHandler::Type& Get(int index) const;
208 
209  // Creates and adds an element using the given prototype, without introducing
210  // a link-time dependency on the concrete message type. This method is used to
211  // implement implicit weak fields. The prototype may be nullptr, in which case
212  // an ImplicitWeakMessage will be used as a placeholder.
213  MessageLite* AddWeak(const MessageLite* prototype);
214 
215  template <typename TypeHandler>
216  void Clear();
217 
218  template <typename TypeHandler>
219  void MergeFrom(const RepeatedPtrFieldBase& other);
220 
221  inline void InternalSwap(RepeatedPtrFieldBase*);
222 
223  protected:
224  template <
225  typename TypeHandler,
227  void Add(typename TypeHandler::Type&& value);
228 
229  template <typename TypeHandler>
230  void RemoveLast();
231  template <typename TypeHandler>
232  void CopyFrom(const RepeatedPtrFieldBase& other);
233 
234  void CloseGap(int start, int num);
235 
236  void Reserve(int new_size);
237 
238  int Capacity() const;
239 
240  template <typename TypeHandler>
241  static inline typename TypeHandler::Type* copy(
242  typename TypeHandler::Type* value) {
243  auto* new_value = TypeHandler::NewFromPrototype(value, nullptr);
244  TypeHandler::Merge(*value, new_value);
245  return new_value;
246  }
247 
248  // Used for constructing iterators.
249  void* const* raw_data() const;
250  void** raw_mutable_data() const;
251 
252  template <typename TypeHandler>
253  typename TypeHandler::Type** mutable_data();
254  template <typename TypeHandler>
255  const typename TypeHandler::Type* const* data() const;
256 
257  template <typename TypeHandler>
258  PROTOBUF_NDEBUG_INLINE void Swap(RepeatedPtrFieldBase* other);
259 
260  void SwapElements(int index1, int index2);
261 
262  template <typename TypeHandler>
263  size_t SpaceUsedExcludingSelfLong() const;
264 
265  // Advanced memory management --------------------------------------
266 
267  // Like Add(), but if there are no cleared objects to use, returns nullptr.
268  template <typename TypeHandler>
269  typename TypeHandler::Type* AddFromCleared();
270 
271  template <typename TypeHandler>
274  AddAllocatedInternal<TypeHandler>(value, t);
275  }
276 
277  template <typename TypeHandler>
278  void UnsafeArenaAddAllocated(typename TypeHandler::Type* value);
279 
280  template <typename TypeHandler>
281  PROTOBUF_NODISCARD typename TypeHandler::Type* ReleaseLast() {
283  return ReleaseLastInternal<TypeHandler>(t);
284  }
285 
286  // Releases last element and returns it, but does not do out-of-arena copy.
287  // And just returns the raw pointer to the contained element in the arena.
288  template <typename TypeHandler>
289  typename TypeHandler::Type* UnsafeArenaReleaseLast();
290 
291  int ClearedCount() const;
292  template <typename TypeHandler>
293  void AddCleared(typename TypeHandler::Type* value);
294  template <typename TypeHandler>
295  PROTOBUF_NODISCARD typename TypeHandler::Type* ReleaseCleared();
296 
297  template <typename TypeHandler>
298  void AddAllocatedInternal(typename TypeHandler::Type* value, std::true_type);
299  template <typename TypeHandler>
300  void AddAllocatedInternal(typename TypeHandler::Type* value, std::false_type);
301 
302  template <typename TypeHandler>
303  PROTOBUF_NOINLINE void AddAllocatedSlowWithCopy(
304  typename TypeHandler::Type* value, Arena* value_arena, Arena* my_arena);
305  template <typename TypeHandler>
306  PROTOBUF_NOINLINE void AddAllocatedSlowWithoutCopy(
307  typename TypeHandler::Type* value);
308 
309  template <typename TypeHandler>
310  typename TypeHandler::Type* ReleaseLastInternal(std::true_type);
311  template <typename TypeHandler>
312  typename TypeHandler::Type* ReleaseLastInternal(std::false_type);
313 
314  template <typename TypeHandler>
315  PROTOBUF_NOINLINE void SwapFallback(RepeatedPtrFieldBase* other);
316 
317  inline Arena* GetArena() const { return arena_; }
318 
319  private:
320  static constexpr int kInitialSize = 0;
321  // A few notes on internal representation:
322  //
323  // We use an indirected approach, with struct Rep, to keep
324  // sizeof(RepeatedPtrFieldBase) equivalent to what it was before arena support
325  // was added, namely, 3 8-byte machine words on x86-64. An instance of Rep is
326  // allocated only when the repeated field is non-empty, and it is a
327  // dynamically-sized struct (the header is directly followed by elements[]).
328  // We place arena_ and current_size_ directly in the object to avoid cache
329  // misses due to the indirection, because these fields are checked frequently.
330  // Placing all fields directly in the RepeatedPtrFieldBase instance costs
331  // significant performance for memory-sensitive workloads.
332  Arena* arena_;
333  int current_size_;
334  int total_size_;
335  struct Rep {
336  int allocated_size;
337  // Here we declare a huge array as a way of approximating C's "flexible
338  // array member" feature without relying on undefined behavior.
339  void* elements[(std::numeric_limits<int>::max() - 2 * sizeof(int)) /
340  sizeof(void*)];
341  };
342  static constexpr size_t kRepHeaderSize = offsetof(Rep, elements);
343  Rep* rep_;
344 
345  template <typename TypeHandler>
346  static inline typename TypeHandler::Type* cast(void* element) {
347  return reinterpret_cast<typename TypeHandler::Type*>(element);
348  }
349  template <typename TypeHandler>
350  static inline const typename TypeHandler::Type* cast(const void* element) {
351  return reinterpret_cast<const typename TypeHandler::Type*>(element);
352  }
353 
354  // Non-templated inner function to avoid code duplication. Takes a function
355  // pointer to the type-specific (templated) inner allocate/merge loop.
356  void MergeFromInternal(const RepeatedPtrFieldBase& other,
357  void (RepeatedPtrFieldBase::*inner_loop)(void**,
358  void**, int,
359  int));
360 
361  template <typename TypeHandler>
362  PROTOBUF_NOINLINE void MergeFromInnerLoop(void** our_elems,
363  void** other_elems, int length,
364  int already_allocated);
365 
366  // Internal helper: extend array space if necessary to contain |extend_amount|
367  // more elements, and return a pointer to the element immediately following
368  // the old list of elements. This interface factors out common behavior from
369  // Reserve() and MergeFrom() to reduce code size. |extend_amount| must be > 0.
370  void** InternalExtend(int extend_amount);
371 
372  // Internal helper for Add: add "obj" as the next element in the
373  // array, including potentially resizing the array with Reserve if
374  // needed
375  void* AddOutOfLineHelper(void* obj);
376 
377  // The reflection implementation needs to call protected methods directly,
378  // reinterpreting pointers as being to Message instead of a specific Message
379  // subclass.
380  friend class ::PROTOBUF_NAMESPACE_ID::Reflection;
381  friend class ::PROTOBUF_NAMESPACE_ID::internal::SwapFieldHelper;
382 
383  // ExtensionSet stores repeated message extensions as
384  // RepeatedPtrField<MessageLite>, but non-lite ExtensionSets need to implement
385  // SpaceUsedLong(), and thus need to call SpaceUsedExcludingSelfLong()
386  // reinterpreting MessageLite as Message. ExtensionSet also needs to make use
387  // of AddFromCleared(), which is not part of the public interface.
388  friend class ExtensionSet;
389 
390  // The MapFieldBase implementation needs to call protected methods directly,
391  // reinterpreting pointers as being to Message instead of a specific Message
392  // subclass.
393  friend class MapFieldBase;
394  friend class MapFieldBaseStub;
395 
396  // The table-driven MergePartialFromCodedStream implementation needs to
397  // operate on RepeatedPtrField<MessageLite>.
399  friend class AccessorHelper;
400  template <typename T>
402 
404 };
405 
406 template <typename GenericType>
407 class GenericTypeHandler {
408  public:
409  typedef GenericType Type;
411 
412  static inline GenericType* New(Arena* arena) {
413  return Arena::CreateMaybeMessage<Type>(arena);
414  }
415  static inline GenericType* New(Arena* arena, GenericType&& value) {
416  return Arena::Create<GenericType>(arena, std::move(value));
417  }
418  static inline GenericType* NewFromPrototype(const GenericType* prototype,
419  Arena* arena = nullptr);
420  static inline void Delete(GenericType* value, Arena* arena) {
421  if (arena == nullptr) {
422  delete value;
423  }
424  }
425  static inline Arena* GetOwningArena(GenericType* value) {
426  return Arena::GetOwningArena<Type>(value);
427  }
428 
429  static inline void Clear(GenericType* value) { value->Clear(); }
430  PROTOBUF_NOINLINE
431  static void Merge(const GenericType& from, GenericType* to);
432  static inline size_t SpaceUsedLong(const GenericType& value) {
433  return value.SpaceUsedLong();
434  }
435 };
436 
437 template <typename GenericType>
439  const GenericType* /* prototype */, Arena* arena) {
440  return New(arena);
441 }
442 template <typename GenericType>
443 void GenericTypeHandler<GenericType>::Merge(const GenericType& from,
444  GenericType* to) {
445  to->MergeFrom(from);
446 }
447 
448 // NewFromPrototype() and Merge() are not defined inline here, as we will need
449 // to do a virtual function dispatch anyways to go from Message* to call
450 // New/Merge.
451 template <>
453  const MessageLite* prototype, Arena* arena);
454 template <>
456  MessageLite* value) {
457  return value->GetOwningArena();
458 }
459 template <>
461  MessageLite* to);
462 template <>
464  value->clear();
465 }
466 template <>
468  std::string* to);
469 
470 // Message specialization bodies defined in message.cc. This split is necessary
471 // to allow proto2-lite (which includes this header) to be independent of
472 // Message.
473 template <>
475  const Message* prototype, Arena* arena);
476 template <>
478  Message* value);
479 
480 class StringTypeHandler {
481  public:
482  typedef std::string Type;
484 
485  static inline std::string* New(Arena* arena) {
486  return Arena::Create<std::string>(arena);
487  }
488  static inline std::string* New(Arena* arena, std::string&& value) {
489  return Arena::Create<std::string>(arena, std::move(value));
490  }
491  static inline std::string* NewFromPrototype(const std::string*,
492  Arena* arena) {
493  return New(arena);
494  }
495  static inline Arena* GetOwningArena(std::string*) { return nullptr; }
496  static inline void Delete(std::string* value, Arena* arena) {
497  if (arena == nullptr) {
498  delete value;
499  }
500  }
501  static inline void Clear(std::string* value) { value->clear(); }
502  static inline void Merge(const std::string& from, std::string* to) {
503  *to = from;
504  }
505  static size_t SpaceUsedLong(const std::string& value) {
506  return sizeof(value) + StringSpaceUsedExcludingSelfLong(value);
507  }
508 };
509 
510 } // namespace internal
511 
512 // RepeatedPtrField is like RepeatedField, but used for repeated strings or
513 // Messages.
514 template <typename Element>
515 class RepeatedPtrField final : private internal::RepeatedPtrFieldBase {
516  public:
517  constexpr RepeatedPtrField();
518  explicit RepeatedPtrField(Arena* arena);
519 
520  RepeatedPtrField(const RepeatedPtrField& other);
521 
522  template <typename Iter,
523  typename = typename std::enable_if<std::is_constructible<
524  Element, decltype(*std::declval<Iter>())>::value>::type>
526 
528 
530 
531  RepeatedPtrField(RepeatedPtrField&& other) noexcept;
532  RepeatedPtrField& operator=(RepeatedPtrField&& other) noexcept;
533 
534  bool empty() const;
535  int size() const;
536 
537  const Element& Get(int index) const;
538  Element* Mutable(int index);
539  Element* Add();
540  void Add(Element&& value);
541  // Append elements in the range [begin, end) after reserving
542  // the appropriate number of elements.
543  template <typename Iter>
544  void Add(Iter begin, Iter end);
545 
546  const Element& operator[](int index) const { return Get(index); }
547  Element& operator[](int index) { return *Mutable(index); }
548 
549  const Element& at(int index) const;
550  Element& at(int index);
551 
552  // Remove the last element in the array.
553  // Ownership of the element is retained by the array.
554  void RemoveLast();
555 
556  // Delete elements with indices in the range [start .. start+num-1].
557  // Caution: implementation moves all elements with indices [start+num .. ].
558  // Calling this routine inside a loop can cause quadratic behavior.
559  void DeleteSubrange(int start, int num);
560 
561  PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear();
562  void MergeFrom(const RepeatedPtrField& other);
563  PROTOBUF_ATTRIBUTE_REINITIALIZES void CopyFrom(const RepeatedPtrField& other);
564 
565  // Replaces the contents with RepeatedPtrField(begin, end).
566  template <typename Iter>
567  PROTOBUF_ATTRIBUTE_REINITIALIZES void Assign(Iter begin, Iter end);
568 
569  // Reserve space to expand the field to at least the given size. This only
570  // resizes the pointer array; it doesn't allocate any objects. If the
571  // array is grown, it will always be at least doubled in size.
572  void Reserve(int new_size);
573 
574  int Capacity() const;
575 
576  // Gets the underlying array. This pointer is possibly invalidated by
577  // any add or remove operation.
578  Element** mutable_data();
579  const Element* const* data() const;
580 
581  // Swap entire contents with "other". If they are on separate arenas, then
582  // copies data.
583  void Swap(RepeatedPtrField* other);
584 
585  // Swap entire contents with "other". Caller should guarantee that either both
586  // fields are on the same arena or both are on the heap. Swapping between
587  // different arenas with this function is disallowed and is caught via
588  // GOOGLE_DCHECK.
589  void UnsafeArenaSwap(RepeatedPtrField* other);
590 
591  // Swap two elements.
592  void SwapElements(int index1, int index2);
593 
594  // STL-like iterator support
597  typedef Element value_type;
599  typedef const value_type& const_reference;
600  typedef value_type* pointer;
601  typedef const value_type* const_pointer;
602  typedef int size_type;
603  typedef ptrdiff_t difference_type;
604 
605  iterator begin();
606  const_iterator begin() const;
607  const_iterator cbegin() const;
608  iterator end();
609  const_iterator end() const;
610  const_iterator cend() const;
611 
612  // Reverse iterator support
613  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
614  typedef std::reverse_iterator<iterator> reverse_iterator;
617  return const_reverse_iterator(end());
618  }
621  return const_reverse_iterator(begin());
622  }
623 
624  // Custom STL-like iterator that iterates over and returns the underlying
625  // pointers to Element rather than Element itself.
628  typedef internal::RepeatedPtrOverPtrsIterator<const Element* const,
629  const void* const>
635 
636  // Returns (an estimate of) the number of bytes used by the repeated field,
637  // excluding sizeof(*this).
638  size_t SpaceUsedExcludingSelfLong() const;
639 
642  }
643 
644  // Advanced memory management --------------------------------------
645  // When hardcore memory management becomes necessary -- as it sometimes
646  // does here at Google -- the following methods may be useful.
647 
648  // Add an already-allocated object, passing ownership to the
649  // RepeatedPtrField.
650  //
651  // Note that some special behavior occurs with respect to arenas:
652  //
653  // (i) if this field holds submessages, the new submessage will be copied if
654  // the original is in an arena and this RepeatedPtrField is either in a
655  // different arena, or on the heap.
656  // (ii) if this field holds strings, the passed-in string *must* be
657  // heap-allocated, not arena-allocated. There is no way to dynamically check
658  // this at runtime, so User Beware.
659  void AddAllocated(Element* value);
660 
661  // Remove the last element and return it, passing ownership to the caller.
662  // Requires: size() > 0
663  //
664  // If this RepeatedPtrField is on an arena, an object copy is required to pass
665  // ownership back to the user (for compatible semantics). Use
666  // UnsafeArenaReleaseLast() if this behavior is undesired.
667  PROTOBUF_NODISCARD Element* ReleaseLast();
668 
669  // Add an already-allocated object, skipping arena-ownership checks. The user
670  // must guarantee that the given object is in the same arena as this
671  // RepeatedPtrField.
672  // It is also useful in legacy code that uses temporary ownership to avoid
673  // copies. Example:
674  // RepeatedPtrField<T> temp_field;
675  // temp_field.UnsafeArenaAddAllocated(new T);
676  // ... // Do something with temp_field
677  // temp_field.UnsafeArenaExtractSubrange(0, temp_field.size(), nullptr);
678  // If you put temp_field on the arena this fails, because the ownership
679  // transfers to the arena at the "AddAllocated" call and is not released
680  // anymore causing a double delete. UnsafeArenaAddAllocated prevents this.
681  void UnsafeArenaAddAllocated(Element* value);
682 
683  // Remove the last element and return it. Unlike ReleaseLast, the returned
684  // pointer is always to the original object. This may be in an arena, and
685  // therefore have the arena's lifetime.
686  // Requires: current_size_ > 0
687  Element* UnsafeArenaReleaseLast();
688 
689  // Extract elements with indices in the range "[start .. start+num-1]".
690  // The caller assumes ownership of the extracted elements and is responsible
691  // for deleting them when they are no longer needed.
692  // If "elements" is non-nullptr, then pointers to the extracted elements
693  // are stored in "elements[0 .. num-1]" for the convenience of the caller.
694  // If "elements" is nullptr, then the caller must use some other mechanism
695  // to perform any further operations (like deletion) on these elements.
696  // Caution: implementation also moves elements with indices [start+num ..].
697  // Calling this routine inside a loop can cause quadratic behavior.
698  //
699  // Memory copying behavior is identical to ReleaseLast(), described above: if
700  // this RepeatedPtrField is on an arena, an object copy is performed for each
701  // returned element, so that all returned element pointers are to
702  // heap-allocated copies. If this copy is not desired, the user should call
703  // UnsafeArenaExtractSubrange().
704  void ExtractSubrange(int start, int num, Element** elements);
705 
706  // Identical to ExtractSubrange() described above, except that no object
707  // copies are ever performed. Instead, the raw object pointers are returned.
708  // Thus, if on an arena, the returned objects must not be freed, because they
709  // will not be heap-allocated objects.
710  void UnsafeArenaExtractSubrange(int start, int num, Element** elements);
711 
712  // When elements are removed by calls to RemoveLast() or Clear(), they
713  // are not actually freed. Instead, they are cleared and kept so that
714  // they can be reused later. This can save lots of CPU time when
715  // repeatedly reusing a protocol message for similar purposes.
716  //
717  // Hardcore programs may choose to manipulate these cleared objects
718  // to better optimize memory management using the following routines.
719 
720  // Get the number of cleared objects that are currently being kept
721  // around for reuse.
722  int ClearedCount() const;
723 #ifndef PROTOBUF_FUTURE_BREAKING_CHANGES
724  // Add an element to the pool of cleared objects, passing ownership to
725  // the RepeatedPtrField. The element must be cleared prior to calling
726  // this method.
727  //
728  // This method cannot be called when the repeated field is on an arena or when
729  // |value| is; both cases will trigger a GOOGLE_DCHECK-failure.
730  void AddCleared(Element* value);
731  // Remove a single element from the cleared pool and return it, passing
732  // ownership to the caller. The element is guaranteed to be cleared.
733  // Requires: ClearedCount() > 0
734  //
735  //
736  // This method cannot be called when the repeated field is on an arena; doing
737  // so will trigger a GOOGLE_DCHECK-failure.
738  PROTOBUF_NODISCARD Element* ReleaseCleared();
739 #endif // !PROTOBUF_FUTURE_BREAKING_CHANGES
740 
741  // Removes the element referenced by position.
742  //
743  // Returns an iterator to the element immediately following the removed
744  // element.
745  //
746  // Invalidates all iterators at or after the removed element, including end().
748 
749  // Removes the elements in the range [first, last).
750  //
751  // Returns an iterator to the element immediately following the removed range.
752  //
753  // Invalidates all iterators at or after the removed range, including end().
755 
756  // Gets the arena on which this RepeatedPtrField stores its elements.
757  inline Arena* GetArena() const;
758 
759  // For internal use only.
760  //
761  // This is public due to it being called by generated code.
764  }
765 
766  private:
767  // Note: RepeatedPtrField SHOULD NOT be subclassed by users.
768  class TypeHandler;
769 
770  // Implementations for ExtractSubrange(). The copying behavior must be
771  // included only if the type supports the necessary operations (e.g.,
772  // MergeFrom()), so we must resolve this at compile time. ExtractSubrange()
773  // uses SFINAE to choose one of the below implementations.
774  void ExtractSubrangeInternal(int start, int num, Element** elements,
776  void ExtractSubrangeInternal(int start, int num, Element** elements,
778 
779  friend class Arena;
780 
781  template <typename T>
782  friend struct WeakRepeatedPtrField;
783 
785 
786 };
787 
788 // implementation ====================================================
789 
790 namespace internal {
791 
793  : arena_(nullptr), current_size_(0), total_size_(0), rep_(nullptr) {}
794 
796  : arena_(arena), current_size_(0), total_size_(0), rep_(nullptr) {}
797 
798 template <typename TypeHandler>
800  if (rep_ != nullptr && arena_ == nullptr) {
801  int n = rep_->allocated_size;
802  void* const* elements = rep_->elements;
803  for (int i = 0; i < n; i++) {
804  TypeHandler::Delete(cast<TypeHandler>(elements[i]), nullptr);
805  }
806 #if defined(__GXX_DELETE_WITH_SIZE__) || defined(__cpp_sized_deallocation)
807  const size_t size = total_size_ * sizeof(elements[0]) + kRepHeaderSize;
808  ::operator delete(static_cast<void*>(rep_), size);
809 #else
810  ::operator delete(static_cast<void*>(rep_));
811 #endif
812  }
813  rep_ = nullptr;
814 }
815 
816 template <typename TypeHandler>
817 inline void RepeatedPtrFieldBase::Swap(RepeatedPtrFieldBase* other) {
818 #ifdef PROTOBUF_FORCE_COPY_IN_SWAP
819  if (GetArena() != nullptr && GetArena() == other->GetArena()) {
820 #else // PROTOBUF_FORCE_COPY_IN_SWAP
821  if (GetArena() == other->GetArena()) {
822 #endif // !PROTOBUF_FORCE_COPY_IN_SWAP
823  InternalSwap(other);
824  } else {
825  SwapFallback<TypeHandler>(other);
826  }
827 }
828 
829 template <typename TypeHandler>
830 void RepeatedPtrFieldBase::SwapFallback(RepeatedPtrFieldBase* other) {
831 #ifdef PROTOBUF_FORCE_COPY_IN_SWAP
832  GOOGLE_DCHECK(GetArena() == nullptr || other->GetArena() != GetArena());
833 #else // PROTOBUF_FORCE_COPY_IN_SWAP
834  GOOGLE_DCHECK(other->GetArena() != GetArena());
835 #endif // !PROTOBUF_FORCE_COPY_IN_SWAP
836 
837  // Copy semantics in this case. We try to improve efficiency by placing the
838  // temporary on |other|'s arena so that messages are copied twice rather than
839  // three times.
840  RepeatedPtrFieldBase temp(other->GetArena());
841  temp.MergeFrom<TypeHandler>(*this);
842  this->Clear<TypeHandler>();
843  this->MergeFrom<TypeHandler>(*other);
844  other->InternalSwap(&temp);
845  temp.Destroy<TypeHandler>(); // Frees rep_ if `other` had no arena.
846 }
847 
848 inline bool RepeatedPtrFieldBase::empty() const { return current_size_ == 0; }
849 
850 inline int RepeatedPtrFieldBase::size() const { return current_size_; }
851 
852 template <typename TypeHandler>
853 inline const typename TypeHandler::Type& RepeatedPtrFieldBase::Get(
854  int index) const {
856  GOOGLE_DCHECK_LT(index, current_size_);
857  return *cast<TypeHandler>(rep_->elements[index]);
858 }
859 
860 template <typename TypeHandler>
861 inline const typename TypeHandler::Type& RepeatedPtrFieldBase::at(
862  int index) const {
864  GOOGLE_CHECK_LT(index, current_size_);
865  return *cast<TypeHandler>(rep_->elements[index]);
866 }
867 
868 template <typename TypeHandler>
869 inline typename TypeHandler::Type& RepeatedPtrFieldBase::at(int index) {
871  GOOGLE_CHECK_LT(index, current_size_);
872  return *cast<TypeHandler>(rep_->elements[index]);
873 }
874 
875 template <typename TypeHandler>
876 inline typename TypeHandler::Type* RepeatedPtrFieldBase::Mutable(int index) {
878  GOOGLE_DCHECK_LT(index, current_size_);
879  return cast<TypeHandler>(rep_->elements[index]);
880 }
881 
882 template <typename TypeHandler>
883 inline void RepeatedPtrFieldBase::Delete(int index) {
885  GOOGLE_DCHECK_LT(index, current_size_);
886  TypeHandler::Delete(cast<TypeHandler>(rep_->elements[index]), arena_);
887 }
888 
889 template <typename TypeHandler>
891  typename TypeHandler::Type* prototype) {
892  if (rep_ != nullptr && current_size_ < rep_->allocated_size) {
893  return cast<TypeHandler>(rep_->elements[current_size_++]);
894  }
895  typename TypeHandler::Type* result =
896  TypeHandler::NewFromPrototype(prototype, arena_);
897  return reinterpret_cast<typename TypeHandler::Type*>(
898  AddOutOfLineHelper(result));
899 }
900 
901 template <typename TypeHandler,
903 inline void RepeatedPtrFieldBase::Add(typename TypeHandler::Type&& value) {
904  if (rep_ != nullptr && current_size_ < rep_->allocated_size) {
905  *cast<TypeHandler>(rep_->elements[current_size_++]) = std::move(value);
906  return;
907  }
908  if (!rep_ || rep_->allocated_size == total_size_) {
909  Reserve(total_size_ + 1);
910  }
911  ++rep_->allocated_size;
912  typename TypeHandler::Type* result =
914  rep_->elements[current_size_++] = result;
915 }
916 
917 template <typename TypeHandler>
918 inline void RepeatedPtrFieldBase::RemoveLast() {
919  GOOGLE_DCHECK_GT(current_size_, 0);
920  TypeHandler::Clear(cast<TypeHandler>(rep_->elements[--current_size_]));
921 }
922 
923 template <typename TypeHandler>
925  const int n = current_size_;
926  GOOGLE_DCHECK_GE(n, 0);
927  if (n > 0) {
928  void* const* elements = rep_->elements;
929  int i = 0;
930  do {
931  TypeHandler::Clear(cast<TypeHandler>(elements[i++]));
932  } while (i < n);
933  current_size_ = 0;
934  }
935 }
936 
937 // To avoid unnecessary code duplication and reduce binary size, we use a
938 // layered approach to implementing MergeFrom(). The toplevel method is
939 // templated, so we get a small thunk per concrete message type in the binary.
940 // This calls a shared implementation with most of the logic, passing a function
941 // pointer to another type-specific piece of code that calls the object-allocate
942 // and merge handlers.
943 template <typename TypeHandler>
944 inline void RepeatedPtrFieldBase::MergeFrom(const RepeatedPtrFieldBase& other) {
945  GOOGLE_DCHECK_NE(&other, this);
946  if (other.current_size_ == 0) return;
947  MergeFromInternal(other,
948  &RepeatedPtrFieldBase::MergeFromInnerLoop<TypeHandler>);
949 }
950 
951 inline void RepeatedPtrFieldBase::MergeFromInternal(
952  const RepeatedPtrFieldBase& other,
953  void (RepeatedPtrFieldBase::*inner_loop)(void**, void**, int, int)) {
954  // Note: wrapper has already guaranteed that other.rep_ != nullptr here.
955  int other_size = other.current_size_;
956  void** other_elements = other.rep_->elements;
957  void** new_elements = InternalExtend(other_size);
958  int allocated_elems = rep_->allocated_size - current_size_;
959  (this->*inner_loop)(new_elements, other_elements, other_size,
960  allocated_elems);
961  current_size_ += other_size;
962  if (rep_->allocated_size < current_size_) {
963  rep_->allocated_size = current_size_;
964  }
965 }
966 
967 // Merges other_elems to our_elems.
968 template <typename TypeHandler>
969 void RepeatedPtrFieldBase::MergeFromInnerLoop(void** our_elems,
970  void** other_elems, int length,
971  int already_allocated) {
972  if (already_allocated < length) {
973  Arena* arena = GetArena();
974  typename TypeHandler::Type* elem_prototype =
975  reinterpret_cast<typename TypeHandler::Type*>(other_elems[0]);
976  for (int i = already_allocated; i < length; i++) {
977  // Allocate a new empty element that we'll merge into below
978  typename TypeHandler::Type* new_elem =
979  TypeHandler::NewFromPrototype(elem_prototype, arena);
980  our_elems[i] = new_elem;
981  }
982  }
983  // Main loop that does the actual merging
984  for (int i = 0; i < length; i++) {
985  // Already allocated: use existing element.
986  typename TypeHandler::Type* other_elem =
987  reinterpret_cast<typename TypeHandler::Type*>(other_elems[i]);
988  typename TypeHandler::Type* new_elem =
989  reinterpret_cast<typename TypeHandler::Type*>(our_elems[i]);
990  TypeHandler::Merge(*other_elem, new_elem);
991  }
992 }
993 
994 template <typename TypeHandler>
995 inline void RepeatedPtrFieldBase::CopyFrom(const RepeatedPtrFieldBase& other) {
996  if (&other == this) return;
997  RepeatedPtrFieldBase::Clear<TypeHandler>();
998  RepeatedPtrFieldBase::MergeFrom<TypeHandler>(other);
999 }
1000 
1001 inline int RepeatedPtrFieldBase::Capacity() const { return total_size_; }
1002 
1003 inline void* const* RepeatedPtrFieldBase::raw_data() const {
1004  return rep_ ? rep_->elements : nullptr;
1005 }
1006 
1007 inline void** RepeatedPtrFieldBase::raw_mutable_data() const {
1008  return rep_ ? const_cast<void**>(rep_->elements) : nullptr;
1009 }
1010 
1011 template <typename TypeHandler>
1012 inline typename TypeHandler::Type** RepeatedPtrFieldBase::mutable_data() {
1013  // TODO(kenton): Breaks C++ aliasing rules. We should probably remove this
1014  // method entirely.
1015  return reinterpret_cast<typename TypeHandler::Type**>(raw_mutable_data());
1016 }
1017 
1018 template <typename TypeHandler>
1019 inline const typename TypeHandler::Type* const* RepeatedPtrFieldBase::data()
1020  const {
1021  // TODO(kenton): Breaks C++ aliasing rules. We should probably remove this
1022  // method entirely.
1023  return reinterpret_cast<const typename TypeHandler::Type* const*>(raw_data());
1024 }
1025 
1026 inline void RepeatedPtrFieldBase::SwapElements(int index1, int index2) {
1027  using std::swap; // enable ADL with fallback
1028  swap(rep_->elements[index1], rep_->elements[index2]);
1029 }
1030 
1031 template <typename TypeHandler>
1032 inline size_t RepeatedPtrFieldBase::SpaceUsedExcludingSelfLong() const {
1033  size_t allocated_bytes = static_cast<size_t>(total_size_) * sizeof(void*);
1034  if (rep_ != nullptr) {
1035  for (int i = 0; i < rep_->allocated_size; ++i) {
1036  allocated_bytes +=
1037  TypeHandler::SpaceUsedLong(*cast<TypeHandler>(rep_->elements[i]));
1038  }
1039  allocated_bytes += kRepHeaderSize;
1040  }
1041  return allocated_bytes;
1042 }
1043 
1044 template <typename TypeHandler>
1045 inline typename TypeHandler::Type* RepeatedPtrFieldBase::AddFromCleared() {
1046  if (rep_ != nullptr && current_size_ < rep_->allocated_size) {
1047  return cast<TypeHandler>(rep_->elements[current_size_++]);
1048  } else {
1049  return nullptr;
1050  }
1051 }
1052 
1053 // AddAllocated version that implements arena-safe copying behavior.
1054 template <typename TypeHandler>
1055 void RepeatedPtrFieldBase::AddAllocatedInternal(
1056  typename TypeHandler::Type* value, std::true_type) {
1057  Arena* element_arena =
1058  reinterpret_cast<Arena*>(TypeHandler::GetOwningArena(value));
1059  Arena* arena = GetArena();
1060  if (arena == element_arena && rep_ && rep_->allocated_size < total_size_) {
1061  // Fast path: underlying arena representation (tagged pointer) is equal to
1062  // our arena pointer, and we can add to array without resizing it (at least
1063  // one slot that is not allocated).
1064  void** elems = rep_->elements;
1065  if (current_size_ < rep_->allocated_size) {
1066  // Make space at [current] by moving first allocated element to end of
1067  // allocated list.
1068  elems[rep_->allocated_size] = elems[current_size_];
1069  }
1070  elems[current_size_] = value;
1071  current_size_ = current_size_ + 1;
1072  rep_->allocated_size = rep_->allocated_size + 1;
1073  } else {
1074  AddAllocatedSlowWithCopy<TypeHandler>(value, element_arena, arena);
1075  }
1076 }
1077 
1078 // Slowpath handles all cases, copying if necessary.
1079 template <typename TypeHandler>
1080 void RepeatedPtrFieldBase::AddAllocatedSlowWithCopy(
1081  // Pass value_arena and my_arena to avoid duplicate virtual call (value) or
1082  // load (mine).
1083  typename TypeHandler::Type* value, Arena* value_arena, Arena* my_arena) {
1084  // Ensure that either the value is in the same arena, or if not, we do the
1085  // appropriate thing: Own() it (if it's on heap and we're in an arena) or copy
1086  // it to our arena/heap (otherwise).
1087  if (my_arena != nullptr && value_arena == nullptr) {
1088  my_arena->Own(value);
1089  } else if (my_arena != value_arena) {
1090  typename TypeHandler::Type* new_value =
1091  TypeHandler::NewFromPrototype(value, my_arena);
1092  TypeHandler::Merge(*value, new_value);
1093  TypeHandler::Delete(value, value_arena);
1094  value = new_value;
1095  }
1096 
1097  UnsafeArenaAddAllocated<TypeHandler>(value);
1098 }
1099 
1100 // AddAllocated version that does not implement arena-safe copying behavior.
1101 template <typename TypeHandler>
1102 void RepeatedPtrFieldBase::AddAllocatedInternal(
1104  if (rep_ && rep_->allocated_size < total_size_) {
1105  // Fast path: underlying arena representation (tagged pointer) is equal to
1106  // our arena pointer, and we can add to array without resizing it (at least
1107  // one slot that is not allocated).
1108  void** elems = rep_->elements;
1109  if (current_size_ < rep_->allocated_size) {
1110  // Make space at [current] by moving first allocated element to end of
1111  // allocated list.
1112  elems[rep_->allocated_size] = elems[current_size_];
1113  }
1114  elems[current_size_] = value;
1115  current_size_ = current_size_ + 1;
1116  ++rep_->allocated_size;
1117  } else {
1118  UnsafeArenaAddAllocated<TypeHandler>(value);
1119  }
1120 }
1121 
1122 template <typename TypeHandler>
1123 void RepeatedPtrFieldBase::UnsafeArenaAddAllocated(
1124  typename TypeHandler::Type* value) {
1125  // Make room for the new pointer.
1126  if (!rep_ || current_size_ == total_size_) {
1127  // The array is completely full with no cleared objects, so grow it.
1128  Reserve(total_size_ + 1);
1129  ++rep_->allocated_size;
1130  } else if (rep_->allocated_size == total_size_) {
1131  // There is no more space in the pointer array because it contains some
1132  // cleared objects awaiting reuse. We don't want to grow the array in this
1133  // case because otherwise a loop calling AddAllocated() followed by Clear()
1134  // would leak memory.
1135  TypeHandler::Delete(cast<TypeHandler>(rep_->elements[current_size_]),
1136  arena_);
1137  } else if (current_size_ < rep_->allocated_size) {
1138  // We have some cleared objects. We don't care about their order, so we
1139  // can just move the first one to the end to make space.
1140  rep_->elements[rep_->allocated_size] = rep_->elements[current_size_];
1141  ++rep_->allocated_size;
1142  } else {
1143  // There are no cleared objects.
1144  ++rep_->allocated_size;
1145  }
1146 
1147  rep_->elements[current_size_++] = value;
1148 }
1149 
1150 // ReleaseLast() for types that implement merge/copy behavior.
1151 template <typename TypeHandler>
1152 inline typename TypeHandler::Type* RepeatedPtrFieldBase::ReleaseLastInternal(
1153  std::true_type) {
1154  // First, release an element.
1155  typename TypeHandler::Type* result = UnsafeArenaReleaseLast<TypeHandler>();
1156  // Now perform a copy if we're on an arena.
1157  Arena* arena = GetArena();
1158 
1159  typename TypeHandler::Type* new_result;
1160 #ifdef PROTOBUF_FORCE_COPY_IN_RELEASE
1161  new_result = copy<TypeHandler>(result);
1162  if (arena == nullptr) delete result;
1163 #else // PROTOBUF_FORCE_COPY_IN_RELEASE
1164  new_result = (arena == nullptr) ? result : copy<TypeHandler>(result);
1165 #endif // !PROTOBUF_FORCE_COPY_IN_RELEASE
1166  return new_result;
1167 }
1168 
1169 // ReleaseLast() for types that *do not* implement merge/copy behavior -- this
1170 // is the same as UnsafeArenaReleaseLast(). Note that we GOOGLE_DCHECK-fail if we're on
1171 // an arena, since the user really should implement the copy operation in this
1172 // case.
1173 template <typename TypeHandler>
1174 inline typename TypeHandler::Type* RepeatedPtrFieldBase::ReleaseLastInternal(
1175  std::false_type) {
1176  GOOGLE_DCHECK(GetArena() == nullptr)
1177  << "ReleaseLast() called on a RepeatedPtrField that is on an arena, "
1178  << "with a type that does not implement MergeFrom. This is unsafe; "
1179  << "please implement MergeFrom for your type.";
1180  return UnsafeArenaReleaseLast<TypeHandler>();
1181 }
1182 
1183 template <typename TypeHandler>
1184 inline typename TypeHandler::Type*
1185 RepeatedPtrFieldBase::UnsafeArenaReleaseLast() {
1186  GOOGLE_DCHECK_GT(current_size_, 0);
1187  typename TypeHandler::Type* result =
1188  cast<TypeHandler>(rep_->elements[--current_size_]);
1189  --rep_->allocated_size;
1190  if (current_size_ < rep_->allocated_size) {
1191  // There are cleared elements on the end; replace the removed element
1192  // with the last allocated element.
1193  rep_->elements[current_size_] = rep_->elements[rep_->allocated_size];
1194  }
1195  return result;
1196 }
1197 
1198 inline int RepeatedPtrFieldBase::ClearedCount() const {
1199  return rep_ ? (rep_->allocated_size - current_size_) : 0;
1200 }
1201 
1202 template <typename TypeHandler>
1203 inline void RepeatedPtrFieldBase::AddCleared(
1204  typename TypeHandler::Type* value) {
1205  GOOGLE_DCHECK(GetArena() == nullptr)
1206  << "AddCleared() can only be used on a RepeatedPtrField not on an arena.";
1207  GOOGLE_DCHECK(TypeHandler::GetOwningArena(value) == nullptr)
1208  << "AddCleared() can only accept values not on an arena.";
1209  if (!rep_ || rep_->allocated_size == total_size_) {
1210  Reserve(total_size_ + 1);
1211  }
1212  rep_->elements[rep_->allocated_size++] = value;
1213 }
1214 
1215 template <typename TypeHandler>
1216 inline typename TypeHandler::Type* RepeatedPtrFieldBase::ReleaseCleared() {
1217  GOOGLE_DCHECK(GetArena() == nullptr)
1218  << "ReleaseCleared() can only be used on a RepeatedPtrField not on "
1219  << "an arena.";
1220  GOOGLE_DCHECK(GetArena() == nullptr);
1221  GOOGLE_DCHECK(rep_ != nullptr);
1222  GOOGLE_DCHECK_GT(rep_->allocated_size, current_size_);
1223  return cast<TypeHandler>(rep_->elements[--rep_->allocated_size]);
1224 }
1225 
1226 } // namespace internal
1227 
1228 // -------------------------------------------------------------------
1229 
1230 template <typename Element>
1231 class RepeatedPtrField<Element>::TypeHandler
1232  : public internal::GenericTypeHandler<Element> {};
1233 
1234 template <>
1235 class RepeatedPtrField<std::string>::TypeHandler
1236  : public internal::StringTypeHandler {};
1237 
1238 template <typename Element>
1239 constexpr RepeatedPtrField<Element>::RepeatedPtrField()
1240  : RepeatedPtrFieldBase() {}
1241 
1242 template <typename Element>
1243 inline RepeatedPtrField<Element>::RepeatedPtrField(Arena* arena)
1244  : RepeatedPtrFieldBase(arena) {}
1245 
1246 template <typename Element>
1247 inline RepeatedPtrField<Element>::RepeatedPtrField(
1248  const RepeatedPtrField& other)
1249  : RepeatedPtrFieldBase() {
1250  MergeFrom(other);
1251 }
1252 
1253 template <typename Element>
1254 template <typename Iter, typename>
1256  Add(begin, end);
1257 }
1258 
1259 template <typename Element>
1261 #ifdef __cpp_if_constexpr
1263 #else
1265 #endif
1266  if (NeedsDestroy()) DestroyProtos();
1267  } else {
1268  Destroy<TypeHandler>();
1269  }
1270 }
1271 
1272 template <typename Element>
1273 inline RepeatedPtrField<Element>& RepeatedPtrField<Element>::operator=(
1274  const RepeatedPtrField& other) {
1275  if (this != &other) CopyFrom(other);
1276  return *this;
1277 }
1278 
1279 template <typename Element>
1280 inline RepeatedPtrField<Element>::RepeatedPtrField(
1281  RepeatedPtrField&& other) noexcept
1282  : RepeatedPtrField() {
1283 #ifdef PROTOBUF_FORCE_COPY_IN_MOVE
1284  CopyFrom(other);
1285 #else // PROTOBUF_FORCE_COPY_IN_MOVE
1286  // We don't just call Swap(&other) here because it would perform 3 copies if
1287  // other is on an arena. This field can't be on an arena because arena
1288  // construction always uses the Arena* accepting constructor.
1289  if (other.GetArena()) {
1290  CopyFrom(other);
1291  } else {
1292  InternalSwap(&other);
1293  }
1294 #endif // !PROTOBUF_FORCE_COPY_IN_MOVE
1295 }
1296 
1297 template <typename Element>
1298 inline RepeatedPtrField<Element>& RepeatedPtrField<Element>::operator=(
1299  RepeatedPtrField&& other) noexcept {
1300  // We don't just call Swap(&other) here because it would perform 3 copies if
1301  // the two fields are on different arenas.
1302  if (this != &other) {
1303  if (GetArena() != other.GetArena()
1304 #ifdef PROTOBUF_FORCE_COPY_IN_MOVE
1305  || GetArena() == nullptr
1306 #endif // !PROTOBUF_FORCE_COPY_IN_MOVE
1307  ) {
1308  CopyFrom(other);
1309  } else {
1310  InternalSwap(&other);
1311  }
1312  }
1313  return *this;
1314 }
1315 
1316 template <typename Element>
1317 inline bool RepeatedPtrField<Element>::empty() const {
1318  return RepeatedPtrFieldBase::empty();
1319 }
1320 
1321 template <typename Element>
1322 inline int RepeatedPtrField<Element>::size() const {
1323  return RepeatedPtrFieldBase::size();
1324 }
1325 
1326 template <typename Element>
1327 inline const Element& RepeatedPtrField<Element>::Get(int index) const {
1328  return RepeatedPtrFieldBase::Get<TypeHandler>(index);
1329 }
1330 
1331 template <typename Element>
1332 inline const Element& RepeatedPtrField<Element>::at(int index) const {
1333  return RepeatedPtrFieldBase::at<TypeHandler>(index);
1334 }
1335 
1336 template <typename Element>
1337 inline Element& RepeatedPtrField<Element>::at(int index) {
1338  return RepeatedPtrFieldBase::at<TypeHandler>(index);
1339 }
1340 
1341 
1342 template <typename Element>
1343 inline Element* RepeatedPtrField<Element>::Mutable(int index) {
1344  return RepeatedPtrFieldBase::Mutable<TypeHandler>(index);
1345 }
1346 
1347 template <typename Element>
1348 inline Element* RepeatedPtrField<Element>::Add() {
1349  return RepeatedPtrFieldBase::Add<TypeHandler>();
1350 }
1351 
1352 template <typename Element>
1353 inline void RepeatedPtrField<Element>::Add(Element&& value) {
1354  RepeatedPtrFieldBase::Add<TypeHandler>(std::move(value));
1355 }
1356 
1357 template <typename Element>
1358 template <typename Iter>
1360  if (std::is_base_of<
1361  std::forward_iterator_tag,
1362  typename std::iterator_traits<Iter>::iterator_category>::value) {
1363  int reserve = std::distance(begin, end);
1364  Reserve(size() + reserve);
1365  }
1366  for (; begin != end; ++begin) {
1367  *Add() = *begin;
1368  }
1369 }
1370 
1371 template <typename Element>
1373  RepeatedPtrFieldBase::RemoveLast<TypeHandler>();
1374 }
1375 
1376 template <typename Element>
1377 inline void RepeatedPtrField<Element>::DeleteSubrange(int start, int num) {
1378  GOOGLE_DCHECK_GE(start, 0);
1379  GOOGLE_DCHECK_GE(num, 0);
1381  for (int i = 0; i < num; ++i) {
1382  RepeatedPtrFieldBase::Delete<TypeHandler>(start + i);
1383  }
1384  UnsafeArenaExtractSubrange(start, num, nullptr);
1385 }
1386 
1387 template <typename Element>
1388 inline void RepeatedPtrField<Element>::ExtractSubrange(int start, int num,
1389  Element** elements) {
1390  typename internal::TypeImplementsMergeBehavior<
1391  typename TypeHandler::Type>::type t;
1392  ExtractSubrangeInternal(start, num, elements, t);
1393 }
1394 
1395 // ExtractSubrange() implementation for types that implement merge/copy
1396 // behavior.
1397 template <typename Element>
1398 inline void RepeatedPtrField<Element>::ExtractSubrangeInternal(
1399  int start, int num, Element** elements, std::true_type) {
1400  GOOGLE_DCHECK_GE(start, 0);
1401  GOOGLE_DCHECK_GE(num, 0);
1403 
1404  if (num == 0) return;
1405 
1406  GOOGLE_DCHECK_NE(elements, nullptr)
1407  << "Releasing elements without transferring ownership is an unsafe "
1408  "operation. Use UnsafeArenaExtractSubrange.";
1409  if (elements == nullptr) {
1410  CloseGap(start, num);
1411  return;
1412  }
1413 
1414  Arena* arena = GetArena();
1415 #ifdef PROTOBUF_FORCE_COPY_IN_RELEASE
1416  // Always copy.
1417  for (int i = 0; i < num; ++i) {
1418  elements[i] = copy<TypeHandler>(
1419  RepeatedPtrFieldBase::Mutable<TypeHandler>(i + start));
1420  }
1421  if (arena == nullptr) {
1422  for (int i = 0; i < num; ++i) {
1423  delete RepeatedPtrFieldBase::Mutable<TypeHandler>(i + start);
1424  }
1425  }
1426 #else // PROTOBUF_FORCE_COPY_IN_RELEASE
1427  // If we're on an arena, we perform a copy for each element so that the
1428  // returned elements are heap-allocated. Otherwise, just forward it.
1429  if (arena != nullptr) {
1430  for (int i = 0; i < num; ++i) {
1431  elements[i] = copy<TypeHandler>(
1432  RepeatedPtrFieldBase::Mutable<TypeHandler>(i + start));
1433  }
1434  } else {
1435  for (int i = 0; i < num; ++i) {
1436  elements[i] = RepeatedPtrFieldBase::Mutable<TypeHandler>(i + start);
1437  }
1438  }
1439 #endif // !PROTOBUF_FORCE_COPY_IN_RELEASE
1440  CloseGap(start, num);
1441 }
1442 
1443 // ExtractSubrange() implementation for types that do not implement merge/copy
1444 // behavior.
1445 template <typename Element>
1446 inline void RepeatedPtrField<Element>::ExtractSubrangeInternal(
1447  int start, int num, Element** elements, std::false_type) {
1448  // This case is identical to UnsafeArenaExtractSubrange(). However, since
1449  // ExtractSubrange() must return heap-allocated objects by contract, and we
1450  // cannot fulfill this contract if we are an on arena, we must GOOGLE_DCHECK() that
1451  // we are not on an arena.
1452  GOOGLE_DCHECK(GetArena() == nullptr)
1453  << "ExtractSubrange() when arena is non-nullptr is only supported when "
1454  << "the Element type supplies a MergeFrom() operation to make copies.";
1455  UnsafeArenaExtractSubrange(start, num, elements);
1456 }
1457 
1458 template <typename Element>
1459 inline void RepeatedPtrField<Element>::UnsafeArenaExtractSubrange(
1460  int start, int num, Element** elements) {
1461  GOOGLE_DCHECK_GE(start, 0);
1462  GOOGLE_DCHECK_GE(num, 0);
1464 
1465  if (num > 0) {
1466  // Save the values of the removed elements if requested.
1467  if (elements != nullptr) {
1468  for (int i = 0; i < num; ++i) {
1469  elements[i] = RepeatedPtrFieldBase::Mutable<TypeHandler>(i + start);
1470  }
1471  }
1472  CloseGap(start, num);
1473  }
1474 }
1475 
1476 template <typename Element>
1477 inline void RepeatedPtrField<Element>::Clear() {
1478  RepeatedPtrFieldBase::Clear<TypeHandler>();
1479 }
1480 
1481 template <typename Element>
1483  const RepeatedPtrField& other) {
1484  RepeatedPtrFieldBase::MergeFrom<TypeHandler>(other);
1485 }
1486 
1487 template <typename Element>
1488 inline void RepeatedPtrField<Element>::CopyFrom(const RepeatedPtrField& other) {
1489  RepeatedPtrFieldBase::CopyFrom<TypeHandler>(other);
1490 }
1491 
1492 template <typename Element>
1493 template <typename Iter>
1495  Clear();
1496  Add(begin, end);
1497 }
1498 
1499 template <typename Element>
1502  return erase(position, position + 1);
1503 }
1504 
1505 template <typename Element>
1507 RepeatedPtrField<Element>::erase(const_iterator first, const_iterator last) {
1508  size_type pos_offset = std::distance(cbegin(), first);
1509  size_type last_offset = std::distance(cbegin(), last);
1510  DeleteSubrange(pos_offset, last_offset - pos_offset);
1511  return begin() + pos_offset;
1512 }
1513 
1514 template <typename Element>
1515 inline Element** RepeatedPtrField<Element>::mutable_data() {
1516  return RepeatedPtrFieldBase::mutable_data<TypeHandler>();
1517 }
1518 
1519 template <typename Element>
1520 inline const Element* const* RepeatedPtrField<Element>::data() const {
1521  return RepeatedPtrFieldBase::data<TypeHandler>();
1522 }
1523 
1524 template <typename Element>
1525 inline void RepeatedPtrField<Element>::Swap(RepeatedPtrField* other) {
1526  if (this == other) return;
1527  RepeatedPtrFieldBase::Swap<TypeHandler>(other);
1528 }
1529 
1530 template <typename Element>
1531 inline void RepeatedPtrField<Element>::UnsafeArenaSwap(
1532  RepeatedPtrField* other) {
1533  if (this == other) return;
1534  RepeatedPtrFieldBase::InternalSwap(other);
1535 }
1536 
1537 template <typename Element>
1538 inline void RepeatedPtrField<Element>::SwapElements(int index1, int index2) {
1539  RepeatedPtrFieldBase::SwapElements(index1, index2);
1540 }
1541 
1542 template <typename Element>
1545 }
1546 
1547 template <typename Element>
1548 inline size_t RepeatedPtrField<Element>::SpaceUsedExcludingSelfLong() const {
1549  return RepeatedPtrFieldBase::SpaceUsedExcludingSelfLong<TypeHandler>();
1550 }
1551 
1552 template <typename Element>
1553 inline void RepeatedPtrField<Element>::AddAllocated(Element* value) {
1554  RepeatedPtrFieldBase::AddAllocated<TypeHandler>(value);
1555 }
1556 
1557 template <typename Element>
1558 inline void RepeatedPtrField<Element>::UnsafeArenaAddAllocated(Element* value) {
1559  RepeatedPtrFieldBase::UnsafeArenaAddAllocated<TypeHandler>(value);
1560 }
1561 
1562 template <typename Element>
1563 inline Element* RepeatedPtrField<Element>::ReleaseLast() {
1564  return RepeatedPtrFieldBase::ReleaseLast<TypeHandler>();
1565 }
1566 
1567 template <typename Element>
1568 inline Element* RepeatedPtrField<Element>::UnsafeArenaReleaseLast() {
1569  return RepeatedPtrFieldBase::UnsafeArenaReleaseLast<TypeHandler>();
1570 }
1571 
1572 template <typename Element>
1573 inline int RepeatedPtrField<Element>::ClearedCount() const {
1574  return RepeatedPtrFieldBase::ClearedCount();
1575 }
1576 
1577 #ifndef PROTOBUF_FUTURE_BREAKING_CHANGES
1578 template <typename Element>
1579 inline void RepeatedPtrField<Element>::AddCleared(Element* value) {
1580  return RepeatedPtrFieldBase::AddCleared<TypeHandler>(value);
1581 }
1582 
1583 template <typename Element>
1584 inline Element* RepeatedPtrField<Element>::ReleaseCleared() {
1585  return RepeatedPtrFieldBase::ReleaseCleared<TypeHandler>();
1586 }
1587 #endif // !PROTOBUF_FUTURE_BREAKING_CHANGES
1588 
1589 template <typename Element>
1590 inline void RepeatedPtrField<Element>::Reserve(int new_size) {
1591  return RepeatedPtrFieldBase::Reserve(new_size);
1592 }
1593 
1594 template <typename Element>
1595 inline int RepeatedPtrField<Element>::Capacity() const {
1596  return RepeatedPtrFieldBase::Capacity();
1597 }
1598 
1599 // -------------------------------------------------------------------
1600 
1601 namespace internal {
1602 
1603 // STL-like iterator implementation for RepeatedPtrField. You should not
1604 // refer to this class directly; use RepeatedPtrField<T>::iterator instead.
1605 //
1606 // The iterator for RepeatedPtrField<T>, RepeatedPtrIterator<T>, is
1607 // very similar to iterator_ptr<T**> in util/gtl/iterator_adaptors.h,
1608 // but adds random-access operators and is modified to wrap a void** base
1609 // iterator (since RepeatedPtrField stores its array as a void* array and
1610 // casting void** to T** would violate C++ aliasing rules).
1611 //
1612 // This code based on net/proto/proto-array-internal.h by Jeffrey Yasskin
1613 // (jyasskin@google.com).
1614 template <typename Element>
1615 class RepeatedPtrIterator {
1616  public:
1618  using iterator_category = std::random_access_iterator_tag;
1620  using difference_type = std::ptrdiff_t;
1621  using pointer = Element*;
1622  using reference = Element&;
1623 
1624  RepeatedPtrIterator() : it_(nullptr) {}
1625  explicit RepeatedPtrIterator(void* const* it) : it_(it) {}
1626 
1627  // Allow "upcasting" from RepeatedPtrIterator<T**> to
1628  // RepeatedPtrIterator<const T*const*>.
1629  template <typename OtherElement>
1631  : it_(other.it_) {
1632  // Force a compiler error if the other type is not convertible to ours.
1633  if (false) {
1634  static_cast<void>([](OtherElement* from) -> Element* { return from; });
1635  }
1636  }
1637 
1638  // dereferenceable
1639  reference operator*() const { return *reinterpret_cast<Element*>(*it_); }
1640  pointer operator->() const { return &(operator*()); }
1641 
1642  // {inc,dec}rementable
1644  ++it_;
1645  return *this;
1646  }
1647  iterator operator++(int) { return iterator(it_++); }
1649  --it_;
1650  return *this;
1651  }
1652  iterator operator--(int) { return iterator(it_--); }
1653 
1654  // equality_comparable
1655  bool operator==(const iterator& x) const { return it_ == x.it_; }
1656  bool operator!=(const iterator& x) const { return it_ != x.it_; }
1657 
1658  // less_than_comparable
1659  bool operator<(const iterator& x) const { return it_ < x.it_; }
1660  bool operator<=(const iterator& x) const { return it_ <= x.it_; }
1661  bool operator>(const iterator& x) const { return it_ > x.it_; }
1662  bool operator>=(const iterator& x) const { return it_ >= x.it_; }
1663 
1664  // addable, subtractable
1666  it_ += d;
1667  return *this;
1668  }
1670  it += d;
1671  return it;
1672  }
1674  it += d;
1675  return it;
1676  }
1678  it_ -= d;
1679  return *this;
1680  }
1682  it -= d;
1683  return it;
1684  }
1685 
1686  // indexable
1687  reference operator[](difference_type d) const { return *(*this + d); }
1688 
1689  // random access iterator
1690  difference_type operator-(const iterator& x) const { return it_ - x.it_; }
1691 
1692  private:
1693  template <typename OtherElement>
1694  friend class RepeatedPtrIterator;
1695 
1696  // The internal iterator.
1697  void* const* it_;
1698 };
1699 
1700 // Provide an iterator that operates on pointers to the underlying objects
1701 // rather than the objects themselves as RepeatedPtrIterator does.
1702 // Consider using this when working with stl algorithms that change
1703 // the array.
1704 // The VoidPtr template parameter holds the type-agnostic pointer value
1705 // referenced by the iterator. It should either be "void *" for a mutable
1706 // iterator, or "const void* const" for a constant iterator.
1707 template <typename Element, typename VoidPtr>
1708 class RepeatedPtrOverPtrsIterator {
1709  public:
1711  using iterator_category = std::random_access_iterator_tag;
1713  using difference_type = std::ptrdiff_t;
1714  using pointer = Element*;
1715  using reference = Element&;
1716 
1718  explicit RepeatedPtrOverPtrsIterator(VoidPtr* it) : it_(it) {}
1719 
1720  // dereferenceable
1721  reference operator*() const { return *reinterpret_cast<Element*>(it_); }
1722  pointer operator->() const { return &(operator*()); }
1723 
1724  // {inc,dec}rementable
1726  ++it_;
1727  return *this;
1728  }
1729  iterator operator++(int) { return iterator(it_++); }
1731  --it_;
1732  return *this;
1733  }
1734  iterator operator--(int) { return iterator(it_--); }
1735 
1736  // equality_comparable
1737  bool operator==(const iterator& x) const { return it_ == x.it_; }
1738  bool operator!=(const iterator& x) const { return it_ != x.it_; }
1739 
1740  // less_than_comparable
1741  bool operator<(const iterator& x) const { return it_ < x.it_; }
1742  bool operator<=(const iterator& x) const { return it_ <= x.it_; }
1743  bool operator>(const iterator& x) const { return it_ > x.it_; }
1744  bool operator>=(const iterator& x) const { return it_ >= x.it_; }
1745 
1746  // addable, subtractable
1748  it_ += d;
1749  return *this;
1750  }
1752  it += d;
1753  return it;
1754  }
1756  it += d;
1757  return it;
1758  }
1760  it_ -= d;
1761  return *this;
1762  }
1764  it -= d;
1765  return it;
1766  }
1767 
1768  // indexable
1769  reference operator[](difference_type d) const { return *(*this + d); }
1770 
1771  // random access iterator
1772  difference_type operator-(const iterator& x) const { return it_ - x.it_; }
1773 
1774  private:
1775  template <typename OtherElement>
1776  friend class RepeatedPtrIterator;
1777 
1778  // The internal iterator.
1779  VoidPtr* it_;
1780 };
1781 
1782 void RepeatedPtrFieldBase::InternalSwap(RepeatedPtrFieldBase* rhs) {
1783  GOOGLE_DCHECK(this != rhs);
1784 
1785  // Swap all fields at once.
1786  auto temp = std::make_tuple(rhs->arena_, rhs->current_size_, rhs->total_size_,
1787  rhs->rep_);
1788  std::tie(rhs->arena_, rhs->current_size_, rhs->total_size_, rhs->rep_) =
1789  std::make_tuple(arena_, current_size_, total_size_, rep_);
1790  std::tie(arena_, current_size_, total_size_, rep_) = temp;
1791 }
1792 
1793 } // namespace internal
1794 
1795 template <typename Element>
1798  return iterator(raw_data());
1799 }
1800 template <typename Element>
1801 inline typename RepeatedPtrField<Element>::const_iterator
1803  return iterator(raw_data());
1804 }
1805 template <typename Element>
1806 inline typename RepeatedPtrField<Element>::const_iterator
1807 RepeatedPtrField<Element>::cbegin() const {
1808  return begin();
1809 }
1810 template <typename Element>
1813  return iterator(raw_data() + size());
1814 }
1815 template <typename Element>
1816 inline typename RepeatedPtrField<Element>::const_iterator
1818  return iterator(raw_data() + size());
1819 }
1820 template <typename Element>
1821 inline typename RepeatedPtrField<Element>::const_iterator
1822 RepeatedPtrField<Element>::cend() const {
1823  return end();
1824 }
1825 
1826 template <typename Element>
1827 inline typename RepeatedPtrField<Element>::pointer_iterator
1828 RepeatedPtrField<Element>::pointer_begin() {
1829  return pointer_iterator(raw_mutable_data());
1830 }
1831 template <typename Element>
1832 inline typename RepeatedPtrField<Element>::const_pointer_iterator
1833 RepeatedPtrField<Element>::pointer_begin() const {
1834  return const_pointer_iterator(const_cast<const void* const*>(raw_data()));
1835 }
1836 template <typename Element>
1837 inline typename RepeatedPtrField<Element>::pointer_iterator
1838 RepeatedPtrField<Element>::pointer_end() {
1839  return pointer_iterator(raw_mutable_data() + size());
1840 }
1841 template <typename Element>
1842 inline typename RepeatedPtrField<Element>::const_pointer_iterator
1843 RepeatedPtrField<Element>::pointer_end() const {
1844  return const_pointer_iterator(
1845  const_cast<const void* const*>(raw_data() + size()));
1846 }
1847 
1848 // Iterators and helper functions that follow the spirit of the STL
1849 // std::back_insert_iterator and std::back_inserter but are tailor-made
1850 // for RepeatedField and RepeatedPtrField. Typical usage would be:
1851 //
1852 // std::copy(some_sequence.begin(), some_sequence.end(),
1853 // RepeatedFieldBackInserter(proto.mutable_sequence()));
1854 //
1855 // Ported by johannes from util/gtl/proto-array-iterators.h
1856 
1857 namespace internal {
1858 
1859 // A back inserter for RepeatedPtrField objects.
1860 template <typename T>
1861 class RepeatedPtrFieldBackInsertIterator {
1862  public:
1863  using iterator_category = std::output_iterator_tag;
1864  using value_type = T;
1865  using pointer = void;
1866  using reference = void;
1867  using difference_type = std::ptrdiff_t;
1868 
1870  : field_(mutable_field) {}
1872  *field_->Add() = value;
1873  return *this;
1874  }
1876  const T* const ptr_to_value) {
1877  *field_->Add() = *ptr_to_value;
1878  return *this;
1879  }
1881  *field_->Add() = std::move(value);
1882  return *this;
1883  }
1887  return *this;
1888  }
1889 
1890  private:
1891  RepeatedPtrField<T>* field_;
1892 };
1893 
1894 // A back inserter for RepeatedPtrFields that inserts by transferring ownership
1895 // of a pointer.
1896 template <typename T>
1897 class AllocatedRepeatedPtrFieldBackInsertIterator {
1898  public:
1899  using iterator_category = std::output_iterator_tag;
1900  using value_type = T;
1901  using pointer = void;
1902  using reference = void;
1903  using difference_type = std::ptrdiff_t;
1904 
1906  RepeatedPtrField<T>* const mutable_field)
1907  : field_(mutable_field) {}
1909  T* const ptr_to_value) {
1910  field_->AddAllocated(ptr_to_value);
1911  return *this;
1912  }
1916  return *this;
1917  }
1918 
1919  private:
1920  RepeatedPtrField<T>* field_;
1921 };
1922 
1923 // Almost identical to AllocatedRepeatedPtrFieldBackInsertIterator. This one
1924 // uses the UnsafeArenaAddAllocated instead.
1925 template <typename T>
1926 class UnsafeArenaAllocatedRepeatedPtrFieldBackInsertIterator {
1927  public:
1928  using iterator_category = std::output_iterator_tag;
1929  using value_type = T;
1930  using pointer = void;
1931  using reference = void;
1932  using difference_type = std::ptrdiff_t;
1933 
1935  RepeatedPtrField<T>* const mutable_field)
1936  : field_(mutable_field) {}
1938  T const* const ptr_to_value) {
1939  field_->UnsafeArenaAddAllocated(const_cast<T*>(ptr_to_value));
1940  return *this;
1941  }
1943  return *this;
1944  }
1946  return *this;
1947  }
1949  int /* unused */) {
1950  return *this;
1951  }
1952 
1953  private:
1954  RepeatedPtrField<T>* field_;
1955 };
1956 
1957 } // namespace internal
1958 
1959 // Provides a back insert iterator for RepeatedPtrField instances,
1960 // similar to std::back_inserter().
1961 template <typename T>
1962 internal::RepeatedPtrFieldBackInsertIterator<T> RepeatedPtrFieldBackInserter(
1963  RepeatedPtrField<T>* const mutable_field) {
1964  return internal::RepeatedPtrFieldBackInsertIterator<T>(mutable_field);
1965 }
1966 
1967 // Special back insert iterator for RepeatedPtrField instances, just in
1968 // case someone wants to write generic template code that can access both
1969 // RepeatedFields and RepeatedPtrFields using a common name.
1970 template <typename T>
1971 internal::RepeatedPtrFieldBackInsertIterator<T> RepeatedFieldBackInserter(
1972  RepeatedPtrField<T>* const mutable_field) {
1973  return internal::RepeatedPtrFieldBackInsertIterator<T>(mutable_field);
1974 }
1975 
1976 // Provides a back insert iterator for RepeatedPtrField instances
1977 // similar to std::back_inserter() which transfers the ownership while
1978 // copying elements.
1979 template <typename T>
1980 internal::AllocatedRepeatedPtrFieldBackInsertIterator<T>
1982  RepeatedPtrField<T>* const mutable_field) {
1983  return internal::AllocatedRepeatedPtrFieldBackInsertIterator<T>(
1984  mutable_field);
1985 }
1986 
1987 // Similar to AllocatedRepeatedPtrFieldBackInserter, using
1988 // UnsafeArenaAddAllocated instead of AddAllocated.
1989 // This is slightly faster if that matters. It is also useful in legacy code
1990 // that uses temporary ownership to avoid copies. Example:
1991 // RepeatedPtrField<T> temp_field;
1992 // temp_field.UnsafeArenaAddAllocated(new T);
1993 // ... // Do something with temp_field
1994 // temp_field.UnsafeArenaExtractSubrange(0, temp_field.size(), nullptr);
1995 // If you put temp_field on the arena this fails, because the ownership
1996 // transfers to the arena at the "AddAllocated" call and is not released anymore
1997 // causing a double delete. Using UnsafeArenaAddAllocated prevents this.
1998 template <typename T>
1999 internal::UnsafeArenaAllocatedRepeatedPtrFieldBackInsertIterator<T>
2001  RepeatedPtrField<T>* const mutable_field) {
2002  return internal::UnsafeArenaAllocatedRepeatedPtrFieldBackInsertIterator<T>(
2003  mutable_field);
2004 }
2005 
2006 extern template class PROTOBUF_EXPORT_TEMPLATE_DECLARE
2007  RepeatedPtrField<std::string>;
2008 
2009 } // namespace protobuf
2010 } // namespace google
2011 
2012 #include <google/protobuf/port_undef.inc>
2013 
2014 #endif // GOOGLE_PROTOBUF_REPEATED_PTR_FIELD_H__
google::protobuf::RepeatedPtrField::iterator
internal::RepeatedPtrIterator< Element > iterator
Definition: repeated_ptr_field.h:595
google::protobuf.internal::GenericTypeHandler::New
static GenericType * New(Arena *arena, GenericType &&value)
Definition: repeated_ptr_field.h:415
google::protobuf.internal::RepeatedPtrFieldBase::current_size_
int current_size_
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:608
google::protobuf.internal::AllocatedRepeatedPtrFieldBackInsertIterator::value_type
T value_type
Definition: repeated_ptr_field.h:1900
_gevent_test_main.result
result
Definition: _gevent_test_main.py:96
google::protobuf.internal::MapFieldBaseStub
Definition: bloaty/third_party/protobuf/src/google/protobuf/map_field_test.cc:55
Type
struct Type Type
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:673
obj
OPENSSL_EXPORT const ASN1_OBJECT * obj
Definition: x509.h:1671
google::protobuf::WeakRepeatedPtrField
Definition: bloaty/third_party/protobuf/src/google/protobuf/implicit_weak_message.h:133
google::protobuf::RepeatedPtrField::rbegin
const_reverse_iterator rbegin() const
Definition: repeated_ptr_field.h:616
google::protobuf.internal::ExtensionSet
Definition: bloaty/third_party/protobuf/src/google/protobuf/extension_set.h:175
google::protobuf::RepeatedPtrField
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/command_line_interface.h:62
google::protobuf::RepeatedPtrField::Add
Element * Add()
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2025
fix_build_deps.temp
temp
Definition: fix_build_deps.py:488
GOOGLE_DCHECK_NE
#define GOOGLE_DCHECK_NE
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/logging.h:197
google::protobuf::RepeatedPtrField::Reserve
void Reserve(int new_size)
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2229
google::protobuf.internal::TypeImplementsMergeBehaviorProbeForMergeFrom
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:392
google::protobuf.internal::RepeatedPtrIterator::RepeatedPtrIterator
RepeatedPtrIterator(void *const *it)
Definition: repeated_ptr_field.h:1625
absl::swap_internal::Swap
void Swap(T &lhs, T &rhs) noexcept(IsNothrowSwappable< T >::value)
Definition: abseil-cpp/absl/meta/type_traits.h:772
google::protobuf.internal::RepeatedPtrFieldBase::cast
static const TypeHandler::Type * cast(const void *element)
Definition: repeated_ptr_field.h:350
regen-readme.it
it
Definition: regen-readme.py:15
google::protobuf.internal::GetArena
Arena * GetArena(MessageLite *msg, int64 arena_offset)
Definition: bloaty/third_party/protobuf/src/google/protobuf/generated_message_table_driven_lite.h:86
google::protobuf::value
const Descriptor::ReservedRange value
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:1954
element
static std::function< Slot &(Slot *)> element
Definition: abseil-cpp/absl/container/internal/hash_policy_traits_test.cc:44
google::protobuf.internal::RepeatedPtrOverPtrsIterator::operator<
bool operator<(const iterator &x) const
Definition: repeated_ptr_field.h:1741
google::protobuf.internal::RepeatedPtrIterator::operator--
iterator & operator--()
Definition: repeated_ptr_field.h:1648
google::protobuf.internal::GenericTypeHandler::Delete
static void Delete(GenericType *value, Arena *arena)
Definition: repeated_ptr_field.h:420
google::protobuf::RepeatedPtrField::InternalSwap
void InternalSwap(RepeatedPtrField *other)
Definition: repeated_ptr_field.h:762
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS
#define GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TypeName)
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/macros.h:40
const
#define const
Definition: bloaty/third_party/zlib/zconf.h:230
bool
bool
Definition: setup_once.h:312
google::protobuf.internal::AllocatedRepeatedPtrFieldBackInsertIterator::pointer
void pointer
Definition: repeated_ptr_field.h:1901
google::protobuf::RepeatedPtrField::ClearedCount
int ClearedCount() const
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2214
google::protobuf.internal::AllocatedRepeatedPtrFieldBackInsertIterator::operator=
AllocatedRepeatedPtrFieldBackInsertIterator< T > & operator=(T *const ptr_to_value)
Definition: repeated_ptr_field.h:1908
reserve
static bool reserve(upb_pb_encoder *e, size_t bytes)
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/upb.c:7630
google::protobuf.internal::RepeatedPtrOverPtrsIterator::operator+=
iterator & operator+=(difference_type d)
Definition: repeated_ptr_field.h:1747
google::protobuf.internal::RepeatedPtrFieldBase::ReleaseLast
PROTOBUF_NODISCARD TypeHandler::Type * ReleaseLast()
Definition: repeated_ptr_field.h:281
google::protobuf.internal::Get
const T & Get(const void *ptr)
Definition: bloaty/third_party/protobuf/src/google/protobuf/generated_message_util.cc:97
google::protobuf.internal::AllocatedRepeatedPtrFieldBackInsertIterator::operator*
AllocatedRepeatedPtrFieldBackInsertIterator< T > & operator*()
Definition: repeated_ptr_field.h:1913
begin
char * begin
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1007
google::protobuf.internal::AllocatedRepeatedPtrFieldBackInsertIterator::difference_type
std::ptrdiff_t difference_type
Definition: repeated_ptr_field.h:1903
google::protobuf.internal::TypeImplementsMergeBehaviorProbeForMergeFrom::CheckType
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:404
google::protobuf.internal::RepeatedPtrFieldBase::total_size_
int total_size_
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:609
google::protobuf::RepeatedPtrField::RepeatedPtrField
RepeatedPtrField()
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:1926
google::protobuf.internal.python_message.MergeFrom
MergeFrom
Definition: bloaty/third_party/protobuf/python/google/protobuf/internal/python_message.py:1339
google::protobuf.internal::RepeatedPtrIterator::operator<
bool operator<(const iterator &x) const
Definition: repeated_ptr_field.h:1659
std::tr1::make_tuple
tuple make_tuple()
Definition: cares/cares/test/gmock-1.8.0/gtest/gtest.h:1619
google::protobuf.internal::RepeatedPtrFieldBackInsertIterator::operator++
RepeatedPtrFieldBackInsertIterator< T > & operator++()
Definition: repeated_ptr_field.h:1885
google::protobuf.internal::UnsafeArenaAllocatedRepeatedPtrFieldBackInsertIterator::operator++
UnsafeArenaAllocatedRepeatedPtrFieldBackInsertIterator< T > & operator++()
Definition: repeated_ptr_field.h:1945
google::protobuf.internal::RepeatedPtrIterator::operator-
friend iterator operator-(iterator it, difference_type d)
Definition: repeated_ptr_field.h:1681
google::protobuf.internal::RepeatedPtrIterator::operator>=
bool operator>=(const iterator &x) const
Definition: repeated_ptr_field.h:1662
position
intern position
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/array.c:487
google::protobuf::RepeatedPtrField::Assign
PROTOBUF_ATTRIBUTE_REINITIALIZES void Assign(Iter begin, Iter end)
GOOGLE_DCHECK
#define GOOGLE_DCHECK
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/logging.h:194
google::protobuf.internal::MergePartialFromCodedStreamHelper
Definition: bloaty/third_party/protobuf/src/google/protobuf/generated_message_table_driven_lite.h:366
google::protobuf.internal::RepeatedPtrFieldBackInsertIterator::value_type
T value_type
Definition: repeated_ptr_field.h:1864
google::protobuf.internal::RepeatedPtrIterator::operator++
iterator & operator++()
Definition: repeated_ptr_field.h:1643
google::protobuf::RepeatedPtrField::rend
const_reverse_iterator rend() const
Definition: repeated_ptr_field.h:620
google::protobuf::RepeatedPtrField::reverse_iterator
std::reverse_iterator< iterator > reverse_iterator
Definition: repeated_ptr_field.h:614
google::protobuf.internal::RepeatedPtrIterator::operator>
bool operator>(const iterator &x) const
Definition: repeated_ptr_field.h:1661
google::protobuf.internal::true_type
integral_constant< bool, true > true_type
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/template_util.h:89
google::protobuf.internal::RepeatedPtrOverPtrsIterator::operator-
difference_type operator-(const iterator &x) const
Definition: repeated_ptr_field.h:1772
google::protobuf::RepeatedPtrField::pointer
value_type * pointer
Definition: repeated_ptr_field.h:600
google::protobuf::python::cmessage::CopyFrom
static PyObject * CopyFrom(CMessage *self, PyObject *arg)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:1862
google::protobuf.internal::RepeatedPtrOverPtrsIterator::reference
Element & reference
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2354
google::protobuf.internal::false_type
integral_constant< bool, false > false_type
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/template_util.h:90
Arena
Definition: arena.c:39
google::protobuf.internal::RepeatedPtrFieldBase::Rep::elements
void * elements[1]
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:612
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
google::protobuf::RepeatedPtrField::end
iterator end()
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2449
google::protobuf.internal::RepeatedPtrIterator::operator<=
bool operator<=(const iterator &x) const
Definition: repeated_ptr_field.h:1660
binary_size.new_size
def new_size
Definition: binary_size.py:124
GOOGLE_CHECK_LT
#define GOOGLE_CHECK_LT(A, B)
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/logging.h:158
google::protobuf::RepeatedPtrField::reference
value_type & reference
Definition: repeated_ptr_field.h:598
google::protobuf::RepeatedPtrField::Get
const Element & Get(int index) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2004
google::protobuf.internal::RepeatedPtrOverPtrsIterator::operator>=
bool operator>=(const iterator &x) const
Definition: repeated_ptr_field.h:1744
New
T * New(Args &&... args)
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:195
google::protobuf::RepeatedPtrField::const_reverse_iterator
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: repeated_ptr_field.h:613
google::protobuf.internal::RepeatedPtrOverPtrsIterator::RepeatedPtrOverPtrsIterator
RepeatedPtrOverPtrsIterator()
Definition: repeated_ptr_field.h:1717
google::protobuf
Definition: bloaty/third_party/protobuf/benchmarks/util/data_proto2_to_proto3_util.h:12
google::protobuf::RepeatedPtrField::data
const Element *const * data() const
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2161
google::protobuf.internal::GenericTypeHandler::New
static GenericType * New(Arena *arena)
Definition: repeated_ptr_field.h:412
google::protobuf::RepeatedPtrField::erase
iterator erase(const_iterator position)
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2142
google::protobuf.internal::RepeatedPtrFieldBackInsertIterator::RepeatedPtrFieldBackInsertIterator
RepeatedPtrFieldBackInsertIterator(RepeatedPtrField< T > *const mutable_field)
Definition: repeated_ptr_field.h:1869
google::protobuf.internal::UnsafeArenaAllocatedRepeatedPtrFieldBackInsertIterator
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2574
google::protobuf.internal::RepeatedPtrIterator::reference
Element & reference
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2261
google::protobuf.internal::RepeatedPtrIterator::operator+
friend iterator operator+(iterator it, const difference_type d)
Definition: repeated_ptr_field.h:1669
to
size_t to
Definition: abseil-cpp/absl/container/internal/layout_test.cc:1385
google::protobuf.internal::RepeatedPtrIterator::operator*
reference operator*() const
Definition: repeated_ptr_field.h:1639
google::protobuf::python::cdescriptor_pool::Add
static PyObject * Add(PyObject *self, PyObject *file_descriptor_proto)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/descriptor_pool.cc:621
google::protobuf::MessageLite
Definition: bloaty/third_party/protobuf/src/google/protobuf/message_lite.h:184
google::protobuf.internal::RepeatedPtrFieldBackInsertIterator::reference
void reference
Definition: repeated_ptr_field.h:1866
google::protobuf.internal::StringTypeHandler::GetOwningArena
static Arena * GetOwningArena(std::string *)
Definition: repeated_ptr_field.h:495
iterator
const typedef MCPhysReg * iterator
Definition: MCRegisterInfo.h:27
google::protobuf::RepeatedPtrField::UnsafeArenaReleaseLast
Element * UnsafeArenaReleaseLast()
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2209
T
#define T(upbtypeconst, upbtype, ctype, default_value)
google::protobuf::RepeatedPtrField::at
const Element & at(int index) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2009
GOOGLE_DCHECK_LT
#define GOOGLE_DCHECK_LT
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/logging.h:198
google::protobuf::RepeatedPtrField::CopyFrom
void CopyFrom(const RepeatedPtrField &other)
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2136
arena
grpc_core::ScopedArenaPtr arena
Definition: binder_transport_test.cc:237
google::protobuf::RepeatedPtrField::empty
bool empty() const
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:1994
google::protobuf::RepeatedPtrField::Mutable
Element * Mutable(int index)
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2020
google::protobuf.internal::RepeatedPtrOverPtrsIterator::operator!=
bool operator!=(const iterator &x) const
Definition: repeated_ptr_field.h:1738
google::protobuf.internal::AllocatedRepeatedPtrFieldBackInsertIterator
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2550
google::protobuf.internal::UnsafeArenaAllocatedRepeatedPtrFieldBackInsertIterator::reference
void reference
Definition: repeated_ptr_field.h:1931
absl::synchronization_internal::Get
static GraphId Get(const IdMap &id, int num)
Definition: abseil-cpp/absl/synchronization/internal/graphcycles_test.cc:44
google::protobuf::AllocatedRepeatedPtrFieldBackInserter
internal::AllocatedRepeatedPtrFieldBackInsertIterator< T > AllocatedRepeatedPtrFieldBackInserter(RepeatedPtrField< T > *const mutable_field)
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2632
kInitialSize
static int kInitialSize
Definition: bloaty/third_party/protobuf/ruby/ext/google/protobuf_c/repeated_field.c:189
google::protobuf.internal::TypeImplementsMergeBehaviorProbeForMergeFrom::HasNoMerge
long HasNoMerge
Definition: repeated_ptr_field.h:110
it_
ClusterStateMap::iterator it_
Definition: xds_resolver.cc:273
google::protobuf::RepeatedPtrField::const_reference
const typedef value_type & const_reference
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:865
google::protobuf.internal::RepeatedPtrIterator::operator+=
iterator & operator+=(difference_type d)
Definition: repeated_ptr_field.h:1665
from
size_t from
Definition: abseil-cpp/absl/container/internal/layout_test.cc:1384
google::protobuf.internal::TypeImplementsMergeBehaviorProbeForMergeFrom::type
std::integral_constant< bool,(sizeof(Check< T >0))==sizeof(HasMerge))> type
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:415
google::protobuf::RepeatedPtrField::ExtractSubrange
void ExtractSubrange(int start, int num, Element **elements)
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2051
google::protobuf.internal::AllocatedRepeatedPtrFieldBackInsertIterator::AllocatedRepeatedPtrFieldBackInsertIterator
AllocatedRepeatedPtrFieldBackInsertIterator(RepeatedPtrField< T > *const mutable_field)
Definition: repeated_ptr_field.h:1905
gen_gtest_pred_impl.Iter
def Iter(n, format, sep='')
Definition: bloaty/third_party/googletest/googletest/scripts/gen_gtest_pred_impl.py:188
google::protobuf.internal::RepeatedPtrOverPtrsIterator::operator-
friend iterator operator-(iterator it, difference_type d)
Definition: repeated_ptr_field.h:1763
start
static uint64_t start
Definition: benchmark-pound.c:74
google::protobuf.internal::TypeImplementsMergeBehavior< std::string >::type
std::true_type type
Definition: repeated_ptr_field.h:141
google::protobuf::RepeatedPtrField::rend
reverse_iterator rend()
Definition: repeated_ptr_field.h:619
google::protobuf.internal::StringTypeHandler::New
static std::string * New(Arena *arena, std::string &&value)
Definition: repeated_ptr_field.h:488
google::protobuf.internal::RepeatedPtrFieldBackInsertIterator::iterator_category
std::output_iterator_tag iterator_category
Definition: repeated_ptr_field.h:1863
google::protobuf.internal::RepeatedPtrIterator::operator++
iterator operator++(int)
Definition: repeated_ptr_field.h:1647
google::protobuf.internal::RepeatedPtrFieldBase::NeedsDestroy
bool NeedsDestroy() const
Definition: repeated_ptr_field.h:182
xds_interop_client.int
int
Definition: xds_interop_client.py:113
google::protobuf.internal::UnsafeArenaAllocatedRepeatedPtrFieldBackInsertIterator::value_type
T value_type
Definition: repeated_ptr_field.h:1929
arena_
Arena * arena_
Definition: client_channel.cc:391
absl::move
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
Definition: abseil-cpp/absl/utility/utility.h:221
end
char * end
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1008
google::protobuf.internal::RepeatedPtrOverPtrsIterator::pointer
Element * pointer
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2353
swap
#define swap(a, b)
Definition: qsort.h:111
google::protobuf.internal::RepeatedPtrFieldBackInsertIterator::operator=
RepeatedPtrFieldBackInsertIterator< T > & operator=(T &&value)
Definition: repeated_ptr_field.h:1880
max
int max
Definition: bloaty/third_party/zlib/examples/enough.c:170
GOOGLE_DCHECK_GT
#define GOOGLE_DCHECK_GT
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/logging.h:200
google::protobuf::RepeatedPtrField::UnsafeArenaSwap
void UnsafeArenaSwap(RepeatedPtrField *other)
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2172
google::protobuf::RepeatedPtrField::operator[]
Element & operator[](int index)
Definition: repeated_ptr_field.h:547
google::protobuf::RepeatedPtrField::~RepeatedPtrField
~RepeatedPtrField()
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:1953
google::protobuf.internal::RepeatedPtrOverPtrsIterator::RepeatedPtrOverPtrsIterator
RepeatedPtrOverPtrsIterator(VoidPtr *it)
Definition: repeated_ptr_field.h:1718
google::protobuf.internal::ToIntSize
int ToIntSize(size_t size)
Definition: bloaty/third_party/protobuf/src/google/protobuf/message_lite.h:105
grpc::protobuf::MessageLite
GRPC_CUSTOM_MESSAGELITE MessageLite
Definition: include/grpcpp/impl/codegen/config_protobuf.h:79
google::protobuf.internal::RepeatedPtrFieldBase::rep_
Rep * rep_
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:617
google::protobuf.internal::RepeatedPtrFieldBackInsertIterator
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2519
google::protobuf::RepeatedPtrField::const_pointer
const typedef value_type * const_pointer
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:867
GOOGLE_CHECK_GE
#define GOOGLE_CHECK_GE(A, B)
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/logging.h:161
google::protobuf.internal::StringTypeHandler::NewFromPrototype
static std::string * NewFromPrototype(const std::string *, Arena *arena)
Definition: repeated_ptr_field.h:491
google::protobuf.internal::RepeatedPtrIterator::operator[]
reference operator[](difference_type d) const
Definition: repeated_ptr_field.h:1687
google::protobuf.internal::RepeatedPtrOverPtrsIterator::operator[]
reference operator[](difference_type d) const
Definition: repeated_ptr_field.h:1769
google::protobuf::RepeatedPtrField::Capacity
int Capacity() const
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2234
google::protobuf.internal::StringTypeHandler::Merge
static void Merge(const std::string &from, std::string *to)
Definition: repeated_ptr_field.h:502
google::protobuf::RepeatedPtrField::RemoveLast
void RemoveLast()
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2035
google::protobuf.internal::RepeatedPtrOverPtrsIterator::operator++
iterator operator++(int)
Definition: repeated_ptr_field.h:1729
google::protobuf.internal::RepeatedPtrIterator::operator-
difference_type operator-(const iterator &x) const
Definition: repeated_ptr_field.h:1690
google::protobuf.internal::StringSpaceUsedExcludingSelfLong
size_t StringSpaceUsedExcludingSelfLong(const std::string &str)
Definition: bloaty/third_party/protobuf/src/google/protobuf/generated_message_util.cc:85
google::protobuf.internal::GenericTypeHandler::Type
GenericType Type
Definition: repeated_ptr_field.h:409
google::protobuf.internal::UnsafeArenaAllocatedRepeatedPtrFieldBackInsertIterator::UnsafeArenaAllocatedRepeatedPtrFieldBackInsertIterator
UnsafeArenaAllocatedRepeatedPtrFieldBackInsertIterator(RepeatedPtrField< T > *const mutable_field)
Definition: repeated_ptr_field.h:1934
google::protobuf.internal::UnsafeArenaAllocatedRepeatedPtrFieldBackInsertIterator::operator*
UnsafeArenaAllocatedRepeatedPtrFieldBackInsertIterator< T > & operator*()
Definition: repeated_ptr_field.h:1942
GOOGLE_DCHECK_GE
#define GOOGLE_DCHECK_GE
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/logging.h:201
google::protobuf.internal::GenericTypeHandler::Merge
static PROTOBUF_NOINLINE void Merge(const GenericType &from, GenericType *to)
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:712
google::protobuf.internal::RepeatedPtrFieldBase::Rep::allocated_size
int allocated_size
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:611
std::swap
void swap(Json::Value &a, Json::Value &b)
Specialize std::swap() for Json::Value.
Definition: third_party/bloaty/third_party/protobuf/conformance/third_party/jsoncpp/json.h:1226
google::protobuf::RepeatedPtrField::pointer_begin
pointer_iterator pointer_begin()
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2465
x
int x
Definition: bloaty/third_party/googletest/googlemock/test/gmock-matchers_test.cc:3610
google::protobuf::RepeatedPtrField::const_iterator
internal::RepeatedPtrIterator< const Element > const_iterator
Definition: repeated_ptr_field.h:596
google::protobuf.internal::RepeatedPtrIterator
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:364
data
char data[kBufferLength]
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1006
google::protobuf.internal::StringTypeHandler
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:755
google::protobuf::RepeatedPtrField::Swap
void Swap(RepeatedPtrField *other)
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2166
google::protobuf::RepeatedPtrField::ReleaseLast
Element * ReleaseLast()
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2204
google::protobuf::RepeatedPtrField::InternalArenaConstructable_
void InternalArenaConstructable_
Definition: repeated_ptr_field.h:784
Delete
void Delete(T *t)
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:208
google::protobuf.internal::StringTypeHandler::New
static std::string * New(Arena *arena)
Definition: repeated_ptr_field.h:485
google::protobuf.internal::RepeatedPtrFieldBackInsertIterator::difference_type
std::ptrdiff_t difference_type
Definition: repeated_ptr_field.h:1867
google::protobuf.text_format.Merge
def Merge(text, message, allow_unknown_extension=False, allow_field_number=False, descriptor_pool=None, allow_unknown_field=False)
Definition: bloaty/third_party/protobuf/python/google/protobuf/text_format.py:659
google::protobuf.internal::RepeatedPtrOverPtrsIterator::operator-=
iterator & operator-=(difference_type d)
Definition: repeated_ptr_field.h:1759
google::protobuf.internal::RepeatedPtrOverPtrsIterator::operator--
iterator & operator--()
Definition: repeated_ptr_field.h:1730
google::protobuf.internal::RepeatedPtrFieldBase::cast
static TypeHandler::Type * cast(void *element)
Definition: repeated_ptr_field.h:346
n
int n
Definition: abseil-cpp/absl/container/btree_test.cc:1080
google::protobuf.internal::RepeatedPtrOverPtrsIterator::operator*
reference operator*() const
Definition: repeated_ptr_field.h:1721
google::protobuf.internal::RepeatedPtrOverPtrsIterator::operator<=
bool operator<=(const iterator &x) const
Definition: repeated_ptr_field.h:1742
google::protobuf.internal::RepeatedPtrIterator::operator--
iterator operator--(int)
Definition: repeated_ptr_field.h:1652
google_benchmark.example.empty
def empty(state)
Definition: example.py:31
google::protobuf::RepeatedPtrField::size_type
int size_type
Definition: repeated_ptr_field.h:602
google::protobuf.internal::RepeatedPtrIterator::pointer
Element * pointer
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2260
google::protobuf::RepeatedPtrField::operator[]
const Element & operator[](int index) const
Definition: repeated_ptr_field.h:546
google::protobuf.internal::TypeImplementsMergeBehavior
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:419
google::protobuf.internal::RepeatedPtrFieldBackInsertIterator::operator++
RepeatedPtrFieldBackInsertIterator< T > & operator++(int)
Definition: repeated_ptr_field.h:1886
google::protobuf::RepeatedPtrField::SpaceUsedExcludingSelfLong
size_t SpaceUsedExcludingSelfLong() const
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2189
google::protobuf::RepeatedPtrField::UnsafeArenaAddAllocated
void UnsafeArenaAddAllocated(Element *value)
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2199
google::protobuf.internal::RepeatedPtrOverPtrsIterator::operator--
iterator operator--(int)
Definition: repeated_ptr_field.h:1734
google::protobuf.internal::RepeatedPtrFieldBase::arena_
Arena * arena_
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:607
google::protobuf::RepeatedPtrField::SwapElements
void SwapElements(int index1, int index2)
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2179
value
const char * value
Definition: hpack_parser_table.cc:165
google::protobuf.internal::AllocatedRepeatedPtrFieldBackInsertIterator::operator++
AllocatedRepeatedPtrFieldBackInsertIterator< T > & operator++()
Definition: repeated_ptr_field.h:1914
google::protobuf::RepeatedPtrField::size
int size() const
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:1999
google::protobuf.internal::AllocatedRepeatedPtrFieldBackInsertIterator::operator++
AllocatedRepeatedPtrFieldBackInsertIterator< T > & operator++(int)
Definition: repeated_ptr_field.h:1915
google::protobuf.internal::RepeatedPtrIterator::iterator_category
std::random_access_iterator_tag iterator_category
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2257
google::protobuf.internal::RepeatedPtrIterator::operator-=
iterator & operator-=(difference_type d)
Definition: repeated_ptr_field.h:1677
google::protobuf::Message
Definition: bloaty/third_party/protobuf/src/google/protobuf/message.h:205
google::protobuf::RepeatedPtrField::mutable_data
Element ** mutable_data()
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2156
phony_transport::Destroy
void Destroy(grpc_transport *)
Definition: bm_call_create.cc:443
google::protobuf.internal::RepeatedPtrFieldBase::copy
static TypeHandler::Type * copy(typename TypeHandler::Type *value)
Definition: repeated_ptr_field.h:241
grpc_core::operator*
Duration operator*(Duration lhs, double rhs)
Definition: src/core/lib/gprpp/time.h:257
google::protobuf::RepeatedPtrField::ExtractSubrangeInternal
void ExtractSubrangeInternal(int start, int num, Element **elements, std::true_type)
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2061
google::protobuf::RepeatedFieldBackInserter
internal::RepeatedFieldBackInsertIterator< T > RepeatedFieldBackInserter(RepeatedField< T > *const mutable_field)
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2605
google::protobuf::RepeatedPtrField::ReleaseCleared
Element * ReleaseCleared()
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2224
google::protobuf.internal::GenericTypeHandler::SpaceUsedLong
static size_t SpaceUsedLong(const GenericType &value)
Definition: repeated_ptr_field.h:432
google::protobuf.internal::RepeatedPtrFieldBase::Rep
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:610
google::protobuf::RepeatedPtrField::AddCleared
void AddCleared(Element *value)
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2219
google::protobuf.internal::RepeatedPtrOverPtrsIterator::operator->
pointer operator->() const
Definition: repeated_ptr_field.h:1722
google::protobuf.internal.python_message.Clear
Clear
Definition: bloaty/third_party/protobuf/python/google/protobuf/internal/python_message.py:1430
google::protobuf.internal::UnsafeArenaAllocatedRepeatedPtrFieldBackInsertIterator::pointer
void pointer
Definition: repeated_ptr_field.h:1930
google::protobuf.internal::StringTypeHandler::Clear
static void Clear(std::string *value)
Definition: repeated_ptr_field.h:501
google::protobuf::RepeatedPtrField::MergeFrom
void MergeFrom(const RepeatedPtrField &other)
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2130
google::protobuf::RepeatedPtrField::difference_type
ptrdiff_t difference_type
Definition: repeated_ptr_field.h:603
google::protobuf.internal::RepeatedPtrIterator::value_type
typename std::remove_const< Element >::type value_type
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2258
google::protobuf::RepeatedPtrField::GetArena
Arena * GetArena() const
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:1021
google::protobuf.internal::GenericTypeHandler::NewFromPrototype
static GenericType * NewFromPrototype(const GenericType *prototype, Arena *arena=NULL)
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:707
absl::str_format_internal::LengthMod::t
@ t
index
int index
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:1184
google::protobuf.internal::RepeatedPtrIterator::operator->
pointer operator->() const
Definition: repeated_ptr_field.h:1640
google::protobuf.internal::RepeatedPtrIterator::RepeatedPtrIterator
RepeatedPtrIterator(const RepeatedPtrIterator< OtherElement > &other)
Definition: repeated_ptr_field.h:1630
std
Definition: grpcpp/impl/codegen/async_unary_call.h:407
google::protobuf.internal::UnsafeArenaAllocatedRepeatedPtrFieldBackInsertIterator::operator++
UnsafeArenaAllocatedRepeatedPtrFieldBackInsertIterator< T > & operator++(int)
Definition: repeated_ptr_field.h:1948
google::protobuf::RepeatedPtrField::SpaceUsedExcludingSelf
int SpaceUsedExcludingSelf() const
Definition: repeated_ptr_field.h:640
google::protobuf.internal::StringTypeHandler::Delete
static void Delete(std::string *value, Arena *arena)
Definition: repeated_ptr_field.h:496
first
StrT first
Definition: cxa_demangle.cpp:4884
google::protobuf.internal::RepeatedPtrOverPtrsIterator::operator==
bool operator==(const iterator &x) const
Definition: repeated_ptr_field.h:1737
google::protobuf.internal::RepeatedPtrIterator::operator+
friend iterator operator+(const difference_type d, iterator it)
Definition: repeated_ptr_field.h:1673
xds_manager.num
num
Definition: xds_manager.py:56
google::protobuf::RepeatedPtrField::Clear
void Clear()
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2125
google::protobuf.internal::TypeImplementsMergeBehaviorProbeForMergeFrom::Check
static HasMerge Check(CheckType< U, void, &U::MergeFrom > *)
google::protobuf::RepeatedPtrField::rbegin
reverse_iterator rbegin()
Definition: repeated_ptr_field.h:615
google::protobuf.internal::IsMovable
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:429
google::protobuf.internal::RepeatedPtrFieldBase::~RepeatedPtrFieldBase
~RepeatedPtrFieldBase()
Definition: repeated_ptr_field.h:171
google::protobuf.internal::StringTypeHandler::Type
std::string Type
Definition: repeated_ptr_field.h:482
google::protobuf.internal::RepeatedPtrFieldBackInsertIterator::operator*
RepeatedPtrFieldBackInsertIterator< T > & operator*()
Definition: repeated_ptr_field.h:1884
google::protobuf.internal::GenericTypeHandler::Clear
static void Clear(GenericType *value)
Definition: repeated_ptr_field.h:429
google::protobuf::RepeatedPtrField::DeleteSubrange
void DeleteSubrange(int start, int num)
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2040
google::protobuf.internal::RepeatedPtrOverPtrsIterator::iterator_category
std::random_access_iterator_tag iterator_category
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2350
google::protobuf.internal::TypeImplementsMergeBehaviorProbeForMergeFrom::HasMerge
char HasMerge
Definition: repeated_ptr_field.h:109
google::protobuf.internal::RepeatedPtrFieldBase
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:451
google::protobuf.internal::GenericTypeHandler::GetOwningArena
static Arena * GetOwningArena(GenericType *value)
Definition: repeated_ptr_field.h:425
google::protobuf.internal::RepeatedPtrFieldBase::AddAllocated
void AddAllocated(typename TypeHandler::Type *value)
Definition: repeated_ptr_field.h:272
google::protobuf.internal::RepeatedPtrIterator::operator==
bool operator==(const iterator &x) const
Definition: repeated_ptr_field.h:1655
google::protobuf.internal::RepeatedPtrOverPtrsIterator::operator+
friend iterator operator+(iterator it, difference_type d)
Definition: repeated_ptr_field.h:1751
google::protobuf.internal::RepeatedPtrFieldBackInsertIterator::operator=
RepeatedPtrFieldBackInsertIterator< T > & operator=(const T *const ptr_to_value)
Definition: repeated_ptr_field.h:1875
internal
Definition: benchmark/test/output_test_helper.cc:20
google::protobuf.internal::MapFieldBase
Definition: bloaty/third_party/protobuf/src/google/protobuf/map_field.h:69
google::protobuf::RepeatedPtrField::pointer_iterator
internal::RepeatedPtrOverPtrsIterator< Element *, void * > pointer_iterator
Definition: repeated_ptr_field.h:627
google::protobuf.internal::UnsafeArenaAllocatedRepeatedPtrFieldBackInsertIterator::operator=
UnsafeArenaAllocatedRepeatedPtrFieldBackInsertIterator< T > & operator=(T const *const ptr_to_value)
Definition: repeated_ptr_field.h:1937
google::protobuf.internal::GenericTypeHandler
Definition: third_party/bloaty/third_party/protobuf/src/google/protobuf/arena.h:93
google::protobuf.internal::RepeatedPtrFieldBase::RepeatedPtrFieldBase
RepeatedPtrFieldBase()
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:1482
google::protobuf::RepeatedPtrFieldBackInserter
internal::RepeatedPtrFieldBackInsertIterator< T > RepeatedPtrFieldBackInserter(RepeatedPtrField< T > *const mutable_field)
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2613
asyncio_get_stats.type
type
Definition: asyncio_get_stats.py:37
google::protobuf::RepeatedPtrField::value_type
Element value_type
Definition: repeated_ptr_field.h:597
google::protobuf.internal::RepeatedPtrOverPtrsIterator::operator+
friend iterator operator+(difference_type d, iterator it)
Definition: repeated_ptr_field.h:1755
google::protobuf.internal::RepeatedPtrIterator::RepeatedPtrIterator
RepeatedPtrIterator()
Definition: repeated_ptr_field.h:1624
google::protobuf.internal::AllocatedRepeatedPtrFieldBackInsertIterator::reference
void reference
Definition: repeated_ptr_field.h:1902
size
voidpf void uLong size
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
google::protobuf::RepeatedPtrField::UnsafeArenaExtractSubrange
void UnsafeArenaExtractSubrange(int start, int num, Element **elements)
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2107
google::protobuf.internal::UnsafeArenaAllocatedRepeatedPtrFieldBackInsertIterator::iterator_category
std::output_iterator_tag iterator_category
Definition: repeated_ptr_field.h:1928
google::protobuf.internal::RepeatedPtrOverPtrsIterator::difference_type
std::ptrdiff_t difference_type
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2352
length
std::size_t length
Definition: abseil-cpp/absl/time/internal/test_util.cc:57
google::protobuf.internal::RepeatedPtrOverPtrsIterator::operator>
bool operator>(const iterator &x) const
Definition: repeated_ptr_field.h:1743
google::protobuf.internal::RepeatedPtrOverPtrsIterator::operator++
iterator & operator++()
Definition: repeated_ptr_field.h:1725
google::protobuf::RepeatedPtrField::operator=
RepeatedPtrField & operator=(const RepeatedPtrField &other)
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:1958
google::protobuf::RepeatedPtrField::cend
const_iterator cend() const
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2459
google::protobuf::UnsafeArenaAllocatedRepeatedPtrFieldBackInserter
internal::UnsafeArenaAllocatedRepeatedPtrFieldBackInsertIterator< T > UnsafeArenaAllocatedRepeatedPtrFieldBackInserter(RepeatedPtrField< T > *const mutable_field)
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2651
testing::Assign
PolymorphicAction< internal::AssignAction< T1, T2 > > Assign(T1 *ptr, T2 val)
Definition: bloaty/third_party/googletest/googlemock/include/gmock/gmock-actions.h:1061
GOOGLE_DCHECK_LE
#define GOOGLE_DCHECK_LE
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/logging.h:199
google::protobuf.internal::RepeatedPtrFieldBackInsertIterator::pointer
void pointer
Definition: repeated_ptr_field.h:1865
google::protobuf::RepeatedPtrField::begin
iterator begin()
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2434
google::protobuf.internal::RepeatedPtrIterator::difference_type
std::ptrdiff_t difference_type
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2259
google::protobuf.internal::AllocatedRepeatedPtrFieldBackInsertIterator::iterator_category
std::output_iterator_tag iterator_category
Definition: repeated_ptr_field.h:1899
google::protobuf::RepeatedPtrField::AddAllocated
void AddAllocated(Element *value)
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2194
google
Definition: bloaty/third_party/protobuf/benchmarks/util/data_proto2_to_proto3_util.h:11
google::protobuf.internal::StringTypeHandler::SpaceUsedLong
static size_t SpaceUsedLong(const std::string &value)
Definition: repeated_ptr_field.h:505
google::protobuf::RepeatedPtrField::cbegin
const_iterator cbegin() const
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2444
Message
Definition: protobuf/php/ext/google/protobuf/message.c:53
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
google::protobuf.internal::RepeatedPtrFieldBase::GetArena
Arena * GetArena() const
Definition: repeated_ptr_field.h:317
google::protobuf.internal::RepeatedPtrOverPtrsIterator
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:366
google::protobuf.internal::AccessorHelper
Definition: bloaty/third_party/protobuf/src/google/protobuf/generated_message_util.cc:434
google::protobuf.internal::RepeatedPtrFieldBase::InternalSwap
void InternalSwap(RepeatedPtrFieldBase *other)
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2421
google::protobuf.internal::RepeatedPtrOverPtrsIterator::value_type
typename std::remove_const< Element >::type value_type
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2351
google::protobuf::RepeatedPtrField::const_pointer_iterator
internal::RepeatedPtrOverPtrsIterator< const Element *const, const void *const > const_pointer_iterator
Definition: repeated_ptr_field.h:630
google::protobuf.internal::RepeatedPtrIterator::operator!=
bool operator!=(const iterator &x) const
Definition: repeated_ptr_field.h:1656
google::protobuf.internal::RepeatedPtrFieldBackInsertIterator::operator=
RepeatedPtrFieldBackInsertIterator< T > & operator=(const T &value)
Definition: repeated_ptr_field.h:1871
google::protobuf.internal::UnsafeArenaAllocatedRepeatedPtrFieldBackInsertIterator::difference_type
std::ptrdiff_t difference_type
Definition: repeated_ptr_field.h:1932
google::protobuf::RepeatedPtrField::pointer_end
pointer_iterator pointer_end()
Definition: bloaty/third_party/protobuf/src/google/protobuf/repeated_field.h:2475


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:01:10