Differences From Artifact [1a162cf272]:
- File src/natools-smaz_implementations-base_64.adb — part of check-in [c49fad3790] at 2017-01-01 21:43:54 on branch trunk — smaz_implementations-base_64: fix multi-block verbatim size computation (user: nat, size: 9791) [annotate] [blame] [check-ins using]
To Artifact [de5cce5c1a]:
- File
src/natools-smaz_implementations-base_64.adb
— part of check-in
[210677c061]
at
2017-01-07 22:53:28
on branch trunk
— smaz_implementations-base_64: rewrite variable-length verbatim code
At some point in the development I changed the base-64 scheme, but failed to propagate it everywhere. Mostly I intend to use only one mode in base-64, and the other one is merely a place-holder, which explains how it got neglected. Now at least it works, even if it's useless. (user: nat, size: 11052) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
39 40 41 42 43 44 45 | begin Tools.Next_Digit (Input, Offset, Code); if Code <= Last_Code then Verbatim_Length := 0; elsif Variable_Length_Verbatim then | > | > > > > | 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | begin Tools.Next_Digit (Input, Offset, Code); if Code <= Last_Code then Verbatim_Length := 0; elsif Variable_Length_Verbatim then if Code < 63 then Verbatim_Length := 63 - Natural (Code); else Tools.Next_Digit (Input, Offset, Code); Verbatim_Length := Natural (Code) + 63 - Natural (Last_Code); end if; Code := 0; elsif Code = 63 then Tools.Next_Digit (Input, Offset, Code); Verbatim_Length := Natural (Code) * 3 + 3; Code := 0; |
︙ | ︙ | |||
112 113 114 115 116 117 118 | (Input_Length : in Positive; Last_Code : in Natools.Smaz_Implementations.Base_64_Tools.Base_64_Digit; Variable_Length_Verbatim : in Boolean) return Ada.Streams.Stream_Element_Count is begin if Variable_Length_Verbatim then declare | > | | > > | | | | 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | (Input_Length : in Positive; Last_Code : in Natools.Smaz_Implementations.Base_64_Tools.Base_64_Digit; Variable_Length_Verbatim : in Boolean) return Ada.Streams.Stream_Element_Count is begin if Variable_Length_Verbatim then declare Largest_Single : constant Positive := 62 - Natural (Last_Code); Largest_Run : constant Positive := 64 + Largest_Single; Run_Count : constant Natural := (Input_Length + Largest_Run - 1) / Largest_Run; Last_Run_Size : constant Positive := Input_Length - (Run_Count - 1) * Largest_Run; Last_Run_Header_Size : constant Ada.Streams.Stream_Element_Count := (if Last_Run_Size > Largest_Single then 2 else 1); begin return Ada.Streams.Stream_Element_Count (Run_Count) * (Tools.Image_Length (Largest_Run) + 2) + Tools.Image_Length (Last_Run_Size) + Last_Run_Header_Size; end; else declare Largest_Prefix : constant Natural := (case Input_Length mod 3 is when 1 => 15 * 3 + 1, when 2 => ((62 - Natural (Last_Code)) * 4 - 1) * 3 + 2, |
︙ | ︙ | |||
173 174 175 176 177 178 179 | Last_Code : in Natools.Smaz_Implementations.Base_64_Tools.Base_64_Digit; Variable_Length_Verbatim : in Boolean) is Index : Positive := Input'First; begin if Variable_Length_Verbatim then declare | > | | | > > > | | > > | > > > > > > > > > > > > > > > > | | > | 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | Last_Code : in Natools.Smaz_Implementations.Base_64_Tools.Base_64_Digit; Variable_Length_Verbatim : in Boolean) is Index : Positive := Input'First; begin if Variable_Length_Verbatim then declare Largest_Single : constant Positive := 62 - Natural (Last_Code); Largest_Run : constant Positive := 64 + Largest_Single; Length, Last : Natural; begin while Index in Input'Range loop Length := Positive'Min (Largest_Run, Input'Last + 1 - Index); if Length > Largest_Single then Write_Code (Output, Offset, 63); Write_Code (Output, Offset, Tools.Base_64_Digit (Length - Largest_Single - 1)); else Write_Code (Output, Offset, Tools.Base_64_Digit (63 - Length)); end if; if Length mod 3 = 1 then Tools.Encode_Single (Input (Index), 0, Output, Offset); Index := Index + 1; Length := Length - 1; elsif Length mod 3 = 2 then Tools.Encode_Double (Input (Index .. Index + 1), 0, Output, Offset); Index := Index + 2; Length := Length - 2; end if; if Length > 0 then Last := Index + Length - 1; Tools.Encode (Input (Index .. Last), Output, Offset); Index := Last + 1; end if; end loop; end; else if Input'Length mod 3 = 1 then declare Extra_Blocks : constant Natural := Natural'Min (15, Input'Length / 3); |
︙ | ︙ |