Skip to content

Commit

Permalink
Merge branch 'topic/vadim/editor-vss' into 'master'
Browse files Browse the repository at this point in the history
Code refactoring and performance improvement

See merge request eng/ide/VSS!354
  • Loading branch information
godunko committed Feb 17, 2025
2 parents 5d95b81 + 5b3f4af commit 324f86a
Show file tree
Hide file tree
Showing 11 changed files with 1,002 additions and 738 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
--
-- Copyright (C) 2021-2024, AdaCore
-- Copyright (C) 2021-2025, AdaCore
--
-- SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
--

-- This version of the package "convert" text handler object into the UTF-8
-- encoded text on modification operations and redispatch operation.

with VSS.Implementation.Text_Handlers.UTF8;
with VSS.Implementation.Text_Handlers.UTF8.Variable;
with VSS.Strings;

package body VSS.Implementation.Text_Handlers.Nul is
Expand Down Expand Up @@ -44,7 +44,8 @@ package body VSS.Implementation.Text_Handlers.Nul is
Code : VSS.Unicode.Code_Point;
Offset : in out VSS.Implementation.Strings.Cursor_Offset) is
begin
VSS.Implementation.Text_Handlers.UTF8.Unsafe_Initialize (Self, 1, 0);
VSS.Implementation.Text_Handlers.UTF8.Variable.Unsafe_Initialize
(Self, 1, 0);
VSS.Implementation.Text_Handlers.Abstract_Text_Handler'Class
(Self).Append (Code, Offset);
end Append;
Expand Down Expand Up @@ -148,7 +149,7 @@ package body VSS.Implementation.Text_Handlers.Nul is
Item : Ada.Strings.UTF_Encoding.UTF_8_String;
Success : out Boolean) is
begin
VSS.Implementation.Text_Handlers.UTF8.Unsafe_Initialize
VSS.Implementation.Text_Handlers.UTF8.Variable.Unsafe_Initialize
(Self, 0, Item'Length);

VSS.Implementation.Text_Handlers.Abstract_Text_Handler'Class
Expand All @@ -164,7 +165,7 @@ package body VSS.Implementation.Text_Handlers.Nul is
Item : Wide_Wide_String;
Success : out Boolean) is
begin
VSS.Implementation.Text_Handlers.UTF8.Unsafe_Initialize
VSS.Implementation.Text_Handlers.UTF8.Variable.Unsafe_Initialize
(Self, 0, Item'Length);
-- Request text data storage size enough to store ASCII text. Storage
-- will reallocated when necessary. It helps to use static storage when
Expand Down Expand Up @@ -205,7 +206,8 @@ package body VSS.Implementation.Text_Handlers.Nul is
(Self);

begin
VSS.Implementation.Text_Handlers.UTF8.Unsafe_Initialize (Self, 1, 0);
VSS.Implementation.Text_Handlers.UTF8.Variable.Unsafe_Initialize
(Self, 1, 0);
Text.Insert (From, Item, Offset);
end Insert;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ pragma Ada_2022;

with Ada.Unchecked_Deallocation;

with VSS.Implementation.Text_Handlers.UTF8.Static;
with VSS.Implementation.Text_Handlers.UTF8.Variable.Static;
with VSS.Strings;

package body VSS.Implementation.Text_Handlers.UTF8.Dynamic is
package body VSS.Implementation.Text_Handlers.UTF8.Variable.Dynamic is

use type VSS.Unicode.UTF16_Code_Unit_Offset;

Expand Down Expand Up @@ -586,7 +586,7 @@ package body VSS.Implementation.Text_Handlers.UTF8.Dynamic is

if Size <= Static.In_Place_Storage_Capacity then
declare
Static : UTF8.Static.Static_UTF8_Handler := (others => <>)
Static : Variable.Static.Static_UTF8_Handler := (others => <>)
with Address => Target_Data.Storage'Address;

begin
Expand Down Expand Up @@ -686,6 +686,32 @@ package body VSS.Implementation.Text_Handlers.UTF8.Dynamic is
Unreference (Self.Pointer);
end Unreference;

------------------------------------
-- UTF8_Constant_Storage_And_Size --
------------------------------------

overriding procedure UTF8_Constant_Storage_And_Size
(Self : Dynamic_UTF8_Handler;
Pointer : out
VSS.Implementation.Interfaces_C.UTF8_Code_Unit_Constant_Access;
Size : out VSS.Unicode.UTF8_Code_Unit_Count) is
begin
Pointer := Self.Pointer.Storage (Self.Pointer.Storage'First)'Access;
Size := Self.Pointer.Size;
end UTF8_Constant_Storage_And_Size;

----------------------------------
-- UTF8_Constant_Storage_Poiner --
----------------------------------

overriding function UTF8_Constant_Storage_Poiner
(Self : Dynamic_UTF8_Handler)
return not null
VSS.Implementation.Interfaces_C.UTF8_Code_Unit_Constant_Access is
begin
return Self.Pointer.Storage (Self.Pointer.Storage'First)'Access;
end UTF8_Constant_Storage_Poiner;

-----------------------
-- UTF8_Insert_Slice --
-----------------------
Expand Down Expand Up @@ -770,16 +796,4 @@ package body VSS.Implementation.Text_Handlers.UTF8.Dynamic is
return Self.Pointer.Size;
end UTF8_Size;

----------------------------------
-- UTF8_Storage_Constant_Poiner --
----------------------------------

overriding function UTF8_Storage_Constant_Poiner
(Self : Dynamic_UTF8_Handler)
return not null
VSS.Implementation.Interfaces_C.UTF8_Code_Unit_Constant_Access is
begin
return Self.Pointer.Storage (Self.Pointer.Storage'First)'Access;
end UTF8_Storage_Constant_Poiner;

end VSS.Implementation.Text_Handlers.UTF8.Dynamic;
end VSS.Implementation.Text_Handlers.UTF8.Variable.Dynamic;
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

with System.Atomic_Counters;

package VSS.Implementation.Text_Handlers.UTF8.Dynamic is
package VSS.Implementation.Text_Handlers.UTF8.Variable.Dynamic is

pragma Preelaborate;

Expand All @@ -32,9 +32,7 @@ package VSS.Implementation.Text_Handlers.UTF8.Dynamic is
pragma Warnings (Off, "bits of ""Dynamic_UTF8_Handler"" unused");
-- Size of the text handler object is fixed.

type Dynamic_UTF8_Handler is
new VSS.Implementation.Text_Handlers.UTF8.Abstract_UTF8_Text with
record
type Dynamic_UTF8_Handler is new Variable_UTF8_Text with record
Pointer : UTF8_String_Data_Access;
end record with Object_Size => 192;

Expand Down Expand Up @@ -176,11 +174,17 @@ package VSS.Implementation.Text_Handlers.UTF8.Dynamic is
overriding function UTF8_Size
(Self : Dynamic_UTF8_Handler) return VSS.Unicode.UTF8_Code_Unit_Count;

overriding function UTF8_Storage_Constant_Poiner
overriding function UTF8_Constant_Storage_Poiner
(Self : Dynamic_UTF8_Handler)
return not null
VSS.Implementation.Interfaces_C.UTF8_Code_Unit_Constant_Access;

overriding procedure UTF8_Constant_Storage_And_Size
(Self : Dynamic_UTF8_Handler;
Pointer : out
VSS.Implementation.Interfaces_C.UTF8_Code_Unit_Constant_Access;
Size : out VSS.Unicode.UTF8_Code_Unit_Count);

-- Subprograms to help code refactoring, some of the will be moved to
-- generic UTF8 fastpath string API, and some moved to the body after
-- that.
Expand All @@ -199,4 +203,4 @@ package VSS.Implementation.Text_Handlers.UTF8.Dynamic is
-- Content of the data will be copied, and old storage block will be
-- unreferenced (and deallocated if it is no longer used).

end VSS.Implementation.Text_Handlers.UTF8.Dynamic;
end VSS.Implementation.Text_Handlers.UTF8.Variable.Dynamic;
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

pragma Ada_2022;

with VSS.Implementation.Text_Handlers.UTF8.Dynamic;
with VSS.Implementation.Text_Handlers.UTF8.Variable.Dynamic;
with VSS.Strings;

package body VSS.Implementation.Text_Handlers.UTF8.Static is
package body VSS.Implementation.Text_Handlers.UTF8.Variable.Static is

use type VSS.Unicode.UTF16_Code_Unit_Offset;

Expand Down Expand Up @@ -68,11 +68,11 @@ package body VSS.Implementation.Text_Handlers.UTF8.Static is
Self.Size + L);

declare
Overlay : Dynamic.Dynamic_UTF8_Handler
renames Dynamic.Dynamic_UTF8_Handler
Overlay : Variable.Dynamic.Dynamic_UTF8_Handler
renames Variable.Dynamic.Dynamic_UTF8_Handler
(VSS.Implementation.Text_Handlers.Abstract_Text_Handler'Class
(Self));
Pointer : Dynamic.UTF8_String_Data_Access
Pointer : Variable.Dynamic.UTF8_String_Data_Access
renames Overlay.Pointer;

begin
Expand Down Expand Up @@ -106,13 +106,14 @@ package body VSS.Implementation.Text_Handlers.UTF8.Static is
VSS.Implementation.Strings.Constant_Handler (Suffix);

begin
if Suffix_Handler.all in Dynamic.Dynamic_UTF8_Handler then
if Suffix_Handler.all in Variable.Dynamic.Dynamic_UTF8_Handler then
-- The suffix use dynamic storage. However, in some cases, result
-- might be stored in the current static storage.

declare
Suffix_Dynamic : Dynamic.Dynamic_UTF8_Handler
renames Dynamic.Dynamic_UTF8_Handler (Suffix_Handler.all);
Suffix_Dynamic : Variable.Dynamic.Dynamic_UTF8_Handler
renames Variable.Dynamic.Dynamic_UTF8_Handler
(Suffix_Handler.all);
Handler :
VSS.Implementation.Strings.Variable_Text_Handler_Access;

Expand Down Expand Up @@ -456,7 +457,7 @@ package body VSS.Implementation.Text_Handlers.UTF8.Static is
Self.Size + L);

declare
Text : Dynamic.Dynamic_UTF8_Handler
Text : Variable.Dynamic.Dynamic_UTF8_Handler
with Import, Convention => Ada, Address => Self'Address;

begin
Expand Down Expand Up @@ -579,6 +580,32 @@ package body VSS.Implementation.Text_Handlers.UTF8.Static is
end return;
end To_UTF_8_String;

------------------------------------
-- UTF8_Constant_Storage_And_Size --
------------------------------------

overriding procedure UTF8_Constant_Storage_And_Size
(Self : Static_UTF8_Handler;
Pointer : out
VSS.Implementation.Interfaces_C.UTF8_Code_Unit_Constant_Access;
Size : out VSS.Unicode.UTF8_Code_Unit_Count) is
begin
Pointer := Self.Storage (Self.Storage'First)'Unchecked_Access;
Size := Self.Size;
end UTF8_Constant_Storage_And_Size;

----------------------------------
-- UTF8_Constant_Storage_Poiner --
----------------------------------

overriding function UTF8_Constant_Storage_Poiner
(Self : Static_UTF8_Handler)
return not null
VSS.Implementation.Interfaces_C.UTF8_Code_Unit_Constant_Access is
begin
return Self.Storage (Self.Storage'First)'Unchecked_Access;
end UTF8_Constant_Storage_Poiner;

-----------------------
-- UTF8_Insert_Slice --
-----------------------
Expand Down Expand Up @@ -612,7 +639,7 @@ package body VSS.Implementation.Text_Handlers.UTF8.Static is
Self.Size + Size);

declare
Text : Dynamic.Dynamic_UTF8_Handler
Text : Variable.Dynamic.Dynamic_UTF8_Handler
with Import, Convention => Ada, Address => Self'Address;

begin
Expand Down Expand Up @@ -694,7 +721,7 @@ package body VSS.Implementation.Text_Handlers.UTF8.Static is
Self.Size - Replace_Size + By_Size);

declare
Text : Dynamic.Dynamic_UTF8_Handler
Text : Variable.Dynamic.Dynamic_UTF8_Handler
with Import, Convention => Ada, Address => Self'Address;

begin
Expand All @@ -720,16 +747,4 @@ package body VSS.Implementation.Text_Handlers.UTF8.Static is
return Self.Size;
end UTF8_Size;

----------------------------------
-- UTF8_Storage_Constant_Poiner --
----------------------------------

overriding function UTF8_Storage_Constant_Poiner
(Self : Static_UTF8_Handler)
return not null
VSS.Implementation.Interfaces_C.UTF8_Code_Unit_Constant_Access is
begin
return Self.Storage (Self.Storage'First)'Unchecked_Access;
end UTF8_Storage_Constant_Poiner;

end VSS.Implementation.Text_Handlers.UTF8.Static;
end VSS.Implementation.Text_Handlers.UTF8.Variable.Static;
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

pragma Ada_2022;

package VSS.Implementation.Text_Handlers.UTF8.Static is
package VSS.Implementation.Text_Handlers.UTF8.Variable.Static is

pragma Preelaborate;

Expand All @@ -22,9 +22,7 @@ package VSS.Implementation.Text_Handlers.UTF8.Static is
VSS.Implementation.Strings.Character_Count
range 0 .. In_Place_Storage_Capacity;

type Static_UTF8_Handler is
new VSS.Implementation.Text_Handlers.UTF8.Abstract_UTF8_Text with
record
type Static_UTF8_Handler is new Variable_UTF8_Text with record
Storage :
VSS.Implementation.UTF8_Encoding.UTF8_Code_Unit_Array
(0 .. In_Place_Storage_Capacity) := [others => 0];
Expand Down Expand Up @@ -153,9 +151,15 @@ package VSS.Implementation.Text_Handlers.UTF8.Static is
overriding function UTF8_Size
(Self : Static_UTF8_Handler) return VSS.Unicode.UTF8_Code_Unit_Count;

overriding function UTF8_Storage_Constant_Poiner
overriding function UTF8_Constant_Storage_Poiner
(Self : Static_UTF8_Handler)
return not null
VSS.Implementation.Interfaces_C.UTF8_Code_Unit_Constant_Access;

end VSS.Implementation.Text_Handlers.UTF8.Static;
overriding procedure UTF8_Constant_Storage_And_Size
(Self : Static_UTF8_Handler;
Pointer : out
VSS.Implementation.Interfaces_C.UTF8_Code_Unit_Constant_Access;
Size : out VSS.Unicode.UTF8_Code_Unit_Count);

end VSS.Implementation.Text_Handlers.UTF8.Variable.Static;
Loading

0 comments on commit 324f86a

Please sign in to comment.