summaryrefslogtreecommitdiff
path: root/gcc/ada/a-coinve.ads
diff options
context:
space:
mode:
authorcharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>2015-10-20 09:56:56 +0000
committercharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>2015-10-20 09:56:56 +0000
commit078a74b8b921d61000f1663cbf10349d94af9bdb (patch)
tree4bf01e9fce36ef4cf64ed5b7df7bb399ce1e7b01 /gcc/ada/a-coinve.ads
parentf0a120e16253542613cbbcad575157e1390afe79 (diff)
downloadgcc-078a74b8b921d61000f1663cbf10349d94af9bdb.tar.gz
2015-10-20 Bob Duff <duff@adacore.com>
* a-coinve.ads, a-coinve.adb: Do the same efficiency improvements that were already done in the definite case (Ada.Containers.Vectors, i.e. a-convec). This includes the ability to suppress checks, the fast path for Append, inlining as appropriate, and special-casing of "for ... of" loops. Reuse the tampering machinery that is now in Ada.Containers. Simplify many operations. * a-convec.ads, a-convec.adb: Change the code to be more similar to a-coinve. * a-finali.ads, a-finali.adb: Expose the "null"-ness of the operations. This may enable optimizations in the future, and seems cleaner anyway. 2015-10-20 Ed Schonberg <schonberg@adacore.com> * sem_ch13.adb (Is_Operational_Item): Attributes related to Ada 2012 iterators are operational items, and can be specified on partial views. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@229033 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/ada/a-coinve.ads')
-rw-r--r--gcc/ada/a-coinve.ads56
1 files changed, 34 insertions, 22 deletions
diff --git a/gcc/ada/a-coinve.ads b/gcc/ada/a-coinve.ads
index d2f7252e560..978b49a455a 100644
--- a/gcc/ada/a-coinve.ads
+++ b/gcc/ada/a-coinve.ads
@@ -343,6 +343,7 @@ package Ada.Containers.Indefinite_Vectors is
private
+ pragma Inline (Append);
pragma Inline (First_Index);
pragma Inline (Last_Index);
pragma Inline (Element);
@@ -351,35 +352,37 @@ private
pragma Inline (Query_Element);
pragma Inline (Update_Element);
pragma Inline (Replace_Element);
+ pragma Inline (Is_Empty);
pragma Inline (Contains);
pragma Inline (Next);
pragma Inline (Previous);
+ package Implementation is new Generic_Implementation;
+ use Implementation;
+
type Element_Access is access Element_Type;
type Elements_Array is array (Index_Type range <>) of Element_Access;
function "=" (L, R : Elements_Array) return Boolean is abstract;
- type Elements_Type (Last : Index_Type) is limited record
+ type Elements_Type (Last : Extended_Index) is limited record
EA : Elements_Array (Index_Type'First .. Last);
end record;
- type Elements_Access is access Elements_Type;
+ type Elements_Access is access all Elements_Type;
+
+ use Finalization;
+ use Streams;
- type Vector is new Ada.Finalization.Controlled with record
- Elements : Elements_Access;
+ type Vector is new Controlled with record
+ Elements : Elements_Access := null;
Last : Extended_Index := No_Index;
- Busy : Natural := 0;
- Lock : Natural := 0;
+ TC : aliased Tamper_Counts;
end record;
overriding procedure Adjust (Container : in out Vector);
-
overriding procedure Finalize (Container : in out Vector);
- use Ada.Finalization;
- use Ada.Streams;
-
procedure Write
(Stream : not null access Root_Stream_Type'Class;
Container : Vector);
@@ -412,16 +415,8 @@ private
for Cursor'Write use Write;
- type Reference_Control_Type is
- new Controlled with record
- Container : Vector_Access;
- end record;
-
- overriding procedure Adjust (Control : in out Reference_Control_Type);
- pragma Inline (Adjust);
-
- overriding procedure Finalize (Control : in out Reference_Control_Type);
- pragma Inline (Finalize);
+ subtype Reference_Control_Type is Implementation.Reference_Control_Type;
+ -- It is necessary to rename this here, so that the compiler can find it
type Constant_Reference_Type
(Element : not null access constant Element_Type) is
@@ -467,16 +462,33 @@ private
for Reference_Type'Read use Read;
- Empty_Vector : constant Vector := (Controlled with null, No_Index, 0, 0);
+ -- Three operations are used to optimize in the expansion of "for ... of"
+ -- loops: the Next(Cursor) procedure in the visible part, and the following
+ -- Pseudo_Reference and Get_Element_Access functions. See Exp_Ch5 for
+ -- details.
+
+ function Pseudo_Reference
+ (Container : aliased Vector'Class) return Reference_Control_Type;
+ pragma Inline (Pseudo_Reference);
+ -- Creates an object of type Reference_Control_Type pointing to the
+ -- container, and increments the Lock. Finalization of this object will
+ -- decrement the Lock.
+
+ function Get_Element_Access
+ (Position : Cursor) return not null Element_Access;
+ -- Returns a pointer to the element designated by Position.
No_Element : constant Cursor := Cursor'(null, Index_Type'First);
+ Empty_Vector : constant Vector := (Controlled with others => <>);
+
type Iterator is new Limited_Controlled and
Vector_Iterator_Interfaces.Reversible_Iterator with
record
Container : Vector_Access;
Index : Index_Type'Base;
- end record;
+ end record
+ with Disable_Controlled => not T_Check;
overriding procedure Finalize (Object : in out Iterator);