Skip to content

Commit 40d80cb

Browse files
committed
Рефакторинг
- Удалена отдельная библиотека управления размером - Знание о лимитах двоичных данных удалено из ядра и оставлено только в StandardLibrary и зависимых от него - Значение опции инжектируется в потребителей через DI
1 parent 27a89b6 commit 40d80cb

28 files changed

Lines changed: 267 additions & 334 deletions

src/1Script.sln

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OneScript.Web.Server", "One
6565
EndProject
6666
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DocumenterTests", "Tests\DocumenterTests\DocumenterTests.csproj", "{BD385142-E9B4-43C1-8F88-067F24E5AF6D}"
6767
EndProject
68-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OneScript.BinaryData", "OneScript.BinaryData\OneScript.BinaryData.csproj", "{5711D446-8CA5-4F01-9DCE-D630FEF3A21B}"
69-
EndProject
7068
Global
7169
GlobalSection(SolutionConfigurationPlatforms) = preSolution
7270
Debug|Any CPU = Debug|Any CPU
@@ -468,24 +466,6 @@ Global
468466
{BD385142-E9B4-43C1-8F88-067F24E5AF6D}.Release|x86.Build.0 = Release|Any CPU
469467
{BD385142-E9B4-43C1-8F88-067F24E5AF6D}.Release|x64.ActiveCfg = Release|Any CPU
470468
{BD385142-E9B4-43C1-8F88-067F24E5AF6D}.Release|x64.Build.0 = Release|Any CPU
471-
{5711D446-8CA5-4F01-9DCE-D630FEF3A21B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
472-
{5711D446-8CA5-4F01-9DCE-D630FEF3A21B}.Debug|Any CPU.Build.0 = Debug|Any CPU
473-
{5711D446-8CA5-4F01-9DCE-D630FEF3A21B}.Debug|x86.ActiveCfg = Debug|Any CPU
474-
{5711D446-8CA5-4F01-9DCE-D630FEF3A21B}.Debug|x86.Build.0 = Debug|Any CPU
475-
{5711D446-8CA5-4F01-9DCE-D630FEF3A21B}.Debug|x64.ActiveCfg = Debug|Any CPU
476-
{5711D446-8CA5-4F01-9DCE-D630FEF3A21B}.Debug|x64.Build.0 = Debug|Any CPU
477-
{5711D446-8CA5-4F01-9DCE-D630FEF3A21B}.LinuxDebug|Any CPU.ActiveCfg = LinuxDebug|Any CPU
478-
{5711D446-8CA5-4F01-9DCE-D630FEF3A21B}.LinuxDebug|Any CPU.Build.0 = LinuxDebug|Any CPU
479-
{5711D446-8CA5-4F01-9DCE-D630FEF3A21B}.LinuxDebug|x86.ActiveCfg = LinuxDebug|Any CPU
480-
{5711D446-8CA5-4F01-9DCE-D630FEF3A21B}.LinuxDebug|x86.Build.0 = LinuxDebug|Any CPU
481-
{5711D446-8CA5-4F01-9DCE-D630FEF3A21B}.LinuxDebug|x64.ActiveCfg = LinuxDebug|Any CPU
482-
{5711D446-8CA5-4F01-9DCE-D630FEF3A21B}.LinuxDebug|x64.Build.0 = LinuxDebug|Any CPU
483-
{5711D446-8CA5-4F01-9DCE-D630FEF3A21B}.Release|Any CPU.ActiveCfg = Release|Any CPU
484-
{5711D446-8CA5-4F01-9DCE-D630FEF3A21B}.Release|Any CPU.Build.0 = Release|Any CPU
485-
{5711D446-8CA5-4F01-9DCE-D630FEF3A21B}.Release|x86.ActiveCfg = Release|Any CPU
486-
{5711D446-8CA5-4F01-9DCE-D630FEF3A21B}.Release|x86.Build.0 = Release|Any CPU
487-
{5711D446-8CA5-4F01-9DCE-D630FEF3A21B}.Release|x64.ActiveCfg = Release|Any CPU
488-
{5711D446-8CA5-4F01-9DCE-D630FEF3A21B}.Release|x64.Build.0 = Release|Any CPU
489469
EndGlobalSection
490470
GlobalSection(SolutionProperties) = preSolution
491471
HideSolutionNode = FALSE

src/OneScript.BinaryData/BinaryDataConfigurationDefaults.cs

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/OneScript.BinaryData/BinaryDataMemoryLimit.cs

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/OneScript.BinaryData/BinaryDataMemoryLimitConfiguration.cs

Lines changed: 0 additions & 91 deletions
This file was deleted.

src/OneScript.BinaryData/BinaryDataRuntimeSettings.cs

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/OneScript.BinaryData/OneScript.BinaryData.csproj

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*----------------------------------------------------------
2+
This Source Code Form is subject to the terms of the
3+
Mozilla Public License, v.2.0. If a copy of the MPL
4+
was not distributed with this file, You can obtain one
5+
at http://mozilla.org/MPL/2.0/.
6+
----------------------------------------------------------*/
7+
8+
using System;
9+
10+
namespace OneScript.StandardLibrary.Binary
11+
{
12+
public static class BinaryDataConstants
13+
{
14+
/// <summary>
15+
/// Максимальный размер массива, доступный в среде выполнения.
16+
/// Де-факто он чуть меньше 2Гб, он же Int32.MaxValue, поэтому используется системная константа <see cref="Array.MaxLength"/>
17+
/// </summary>
18+
public static readonly int SYSTEM_IN_MEMORY_LIMIT = Array.MaxLength;
19+
20+
/// <summary>
21+
/// Размер двоичных данных, хранимый в памяти по умолчанию.
22+
/// </summary>
23+
public const int DEFAULT_IN_MEMORY_LIMIT = 1024 * 1024 * 50;
24+
}
25+
}

src/OneScript.StandardLibrary/Binary/BinaryDataContext.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ This Source Code Form is subject to the terms of the
1212
using OneScript.Contexts;
1313
using OneScript.Exceptions;
1414
using OneScript.Types;
15-
using OneScript.BinaryData;
1615
using OneScript.Values;
1716
using ScriptEngine.Machine;
1817
using ScriptEngine.Machine.Contexts;
@@ -25,32 +24,32 @@ public sealed class BinaryDataContext : AutoContext<BinaryDataContext>, IDisposa
2524
private byte[] _buffer;
2625
private BackingTemporaryFile _backingFile;
2726

28-
public BinaryDataContext(string filename)
27+
public BinaryDataContext(string filename, int inMemLimit)
2928
{
3029
using var fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
31-
ReadFromStream(fs);
30+
ReadFromStream(fs, inMemLimit);
3231
}
3332

3433
public BinaryDataContext(byte[] buffer)
3534
{
3635
_buffer = buffer ?? throw new ArgumentNullException(nameof(buffer));
3736
}
3837

39-
public BinaryDataContext(Stream stream)
38+
public BinaryDataContext(Stream stream, int inMemLimit)
4039
{
4140
long pos = 0;
42-
ReadFromStream(stream);
41+
ReadFromStream(stream, inMemLimit);
4342
stream.Position = pos;
4443
}
45-
44+
4645
/// <summary>
4746
/// Признак хранения данных в памяти
4847
/// </summary>
4948
public bool InMemory => _backingFile == null;
5049

51-
private void ReadFromStream(Stream stream)
50+
private void ReadFromStream(Stream stream, int inMemLimit)
5251
{
53-
if (stream.Length < BinaryDataRuntimeSettings.GetEffectiveInMemoryMaxBytes())
52+
if (stream.Length < inMemLimit)
5453
{
5554
LoadToBuffer(stream);
5655
}
@@ -198,9 +197,9 @@ public GenericStream OpenStreamForRead()
198197
}
199198

200199
[ScriptConstructor(Name = "На основании файла")]
201-
public static BinaryDataContext Constructor(string filename)
200+
public static BinaryDataContext Constructor(TypeActivationContext ctx, string filename)
202201
{
203-
return new BinaryDataContext(filename);
202+
return new BinaryDataContext(filename, ctx.Services.Resolve<IBinaryDataMemoryLimit>().MaxBytesInMemory);
204203
}
205204

206205
public override bool Equals(BslValue other)

0 commit comments

Comments
 (0)