Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ public class TextNameScanBenchmarks
static readonly Type NameSet = Core.GetType("Open.Database.Extensions.NameSet", throwOnError: true)!;

static readonly Func<string, string, string?> Scan
= Cache.GetMethod("Scan", BindingFlags.Static | BindingFlags.NonPublic)!.CreateDelegate<Func<string, string, string?>>();
= Cache.GetMethod("Scan", BindingFlags.Static | BindingFlags.Public)!.CreateDelegate<Func<string, string, string?>>();

// The new path's lookup: null for a text that is not interned (the text is then scanned).
static readonly Func<string, object?> Get
= Cache.GetMethod("Get", BindingFlags.Static | BindingFlags.NonPublic)!.CreateDelegate<Func<string, object?>>();
= Cache.GetMethod("Get", BindingFlags.Static | BindingFlags.Public)!.CreateDelegate<Func<string, object?>>();

// The parsed way: read the text into a set of names and match each argument in it, as the set of a remembered text does.
static readonly Func<string, string, string?> Parse
Expand All @@ -55,7 +55,7 @@ static readonly Func<string, ImmutableArray<string>> Tokens
static Func<ImmutableArray<string>, object> BuildMakeSet()
{
ParameterExpression names = Expression.Parameter(typeof(ImmutableArray<string>));
ConstructorInfo constructor = NameSet.GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic)[0];
ConstructorInfo constructor = NameSet.GetConstructors(BindingFlags.Instance | BindingFlags.Public)[0];
NewExpression made = constructor.GetParameters().Length == 1
? Expression.New(constructor, names)
: Expression.New(constructor, names, Expression.Constant(false));
Expand All @@ -67,7 +67,7 @@ static Func<ImmutableArray<string>, object> BuildMakeSet()
ParameterExpression set = Expression.Parameter(typeof(object));
ParameterExpression expression = Expression.Parameter(typeof(string));
ParameterExpression procedure = Expression.Parameter(typeof(string));
MethodInfo match = NameSet.GetMethod("Match", BindingFlags.Instance | BindingFlags.NonPublic)!;
MethodInfo match = NameSet.GetMethod("Match", BindingFlags.Instance | BindingFlags.Public)!;
return Expression.Lambda<Func<object, string, string, string?>>(
Expression.Call(Expression.Convert(set, NameSet), match, expression, procedure),
set,
Expand Down
6 changes: 3 additions & 3 deletions Source/Channel/ChannelPump.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal static class ChannelPump
/// </param>
/// <include file="../Core/Mapped.docs.xml" path="docs/members[@name='token-pass']/*" />
/// <returns>The number of rows handed to the writer.</returns>
internal static async ValueTask<long> Run<T, TFeed>(
public static async ValueTask<long> Run<T, TFeed>(
TFeed feed,
ChannelWriter<T> writer,
bool complete,
Expand Down Expand Up @@ -67,7 +67,7 @@ internal static async ValueTask<long> Run<T, TFeed>(
/// </returns>
// Not async: with room now, it returns the enumerator with no frame and
// nothing allocated. Only a wait, a closed writer or a failure goes on.
internal static ValueTask<IAsyncEnumerator<TItem>?> Open<T, TItem>(
public static ValueTask<IAsyncEnumerator<TItem>?> Open<T, TItem>(
IAsyncEnumerable<TItem> stream,
ChannelWriter<T> writer,
CancellationToken cancellationToken)
Expand Down Expand Up @@ -127,7 +127,7 @@ await rows.DisposeAsync()
/// </summary>
/// <returns>The position of the first row not written.</returns>
// The only code that holds a span: nothing can await while it lives.
internal static int TryWriteFrom<T>(
public static int TryWriteFrom<T>(
ChannelWriter<T> writer,
ReadOnlyMemory<T> chunk,
int start)
Expand Down
87 changes: 32 additions & 55 deletions Source/Core/BoundCall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -366,13 +366,7 @@ public static ValueTask<T> ExecuteReturnAsync<T>(
}

// A capture of the return code and this would read it twice.
if (call.Captures?.ReturnReader is { } returnReader)
{
throw call.Captures.Refuse(
new InvalidOperationException(
CaptureMessages.ReturnBeside(returnReader)),
cancellationToken);
}
call.Captures?.ThrowIfReturnBeside(cancellationToken);

return DbQueryRunner.ReturnAsync<T>(
definition,
Expand All @@ -394,6 +388,17 @@ static BoundCall<TKind> WithCapture<TKind>(
CaptureSet.WithOnDefinition(
call.Captures, source, call.Call.Definition.Kind));

// The call with the capture, and the capture's handle for the caller.
static BoundCall<TKind> WithCapture<TKind, TValue>(
BoundCall<TKind> call,
CaptureSource<TValue> source,
out DbCapture<TValue> capture)
{
BoundCall<TKind> captured = WithCapture(call, source);
capture = new(source);
return captured;
}

/// <summary>
/// Reads the output parameters into a <typeparamref name="TOut"/> when the
/// write runs: a model by its members, or one value by the name of the
Expand All @@ -407,12 +412,7 @@ public static BoundCall<NonQueryKind> CaptureOutput<TOut>(
this BoundCall<NonQueryKind> call,
out DbCapture<TOut> output,
[CallerArgumentExpression(nameof(output))] string? name = null)
{
CaptureSource<TOut> source = Captures.Output<TOut>(name);
BoundCall<NonQueryKind> captured = WithCapture(call, source);
output = new(source);
return captured;
}
=> WithCapture(call, Captures.Output<TOut>(name), out output);

/// <summary>
/// Reads one <see cref="decimal"/> output parameter of the given precision
Expand All @@ -429,12 +429,10 @@ public static BoundCall<NonQueryKind> CaptureOutput(
byte precision,
byte scale,
[CallerArgumentExpression(nameof(value))] string? name = null)
{
CaptureSource<decimal> source = Captures.Shaped(name, precision, scale);
BoundCall<NonQueryKind> captured = WithCapture(call, source);
value = new(source);
return captured;
}
=> WithCapture(
call,
Captures.Shaped(name, precision, scale),
out value);

/// <summary>
/// Reads one <see cref="decimal"/> output parameter of the given precision
Expand All @@ -450,12 +448,10 @@ public static BoundCall<NonQueryKind> CaptureOutputDecimal(
byte precision,
byte scale,
[CallerArgumentExpression(nameof(value))] string? name = null)
{
CaptureSource<decimal?> source = Captures.Decimal(name, precision, scale);
BoundCall<NonQueryKind> captured = WithCapture(call, source);
value = new(source);
return captured;
}
=> WithCapture(
call,
Captures.Decimal(name, precision, scale),
out value);

/// <summary>
/// Reads the stored procedure's return code, converted to
Expand All @@ -467,12 +463,7 @@ public static BoundCall<NonQueryKind> CaptureOutputDecimal(
public static BoundCall<NonQueryKind> CaptureReturn<TValue>(
this BoundCall<NonQueryKind> call,
out DbCapture<TValue> returnCode)
{
CaptureSource<TValue> source = Captures.Return<TValue>();
BoundCall<NonQueryKind> captured = WithCapture(call, source);
returnCode = new(source);
return captured;
}
=> WithCapture(call, Captures.Return<TValue>(), out returnCode);

/// <summary>
/// Reads the output parameters into a <typeparamref name="TOut"/> when the
Expand All @@ -488,12 +479,7 @@ public static BoundCall<ScalarKind<T>> CaptureOutput<T, TOut>(
this BoundCall<ScalarKind<T>> call,
out DbCapture<TOut> output,
[CallerArgumentExpression(nameof(output))] string? name = null)
{
CaptureSource<TOut> source = Captures.Output<TOut>(name);
BoundCall<ScalarKind<T>> captured = WithCapture(call, source);
output = new(source);
return captured;
}
=> WithCapture(call, Captures.Output<TOut>(name), out output);

/// <summary>
/// Reads one <see cref="decimal"/> output parameter of the given precision
Expand All @@ -511,12 +497,10 @@ public static BoundCall<ScalarKind<T>> CaptureOutput<T>(
byte precision,
byte scale,
[CallerArgumentExpression(nameof(value))] string? name = null)
{
CaptureSource<decimal> source = Captures.Shaped(name, precision, scale);
BoundCall<ScalarKind<T>> captured = WithCapture(call, source);
value = new(source);
return captured;
}
=> WithCapture(
call,
Captures.Shaped(name, precision, scale),
out value);

/// <summary>
/// Reads one <see cref="decimal"/> output parameter of the given precision
Expand All @@ -533,12 +517,10 @@ public static BoundCall<ScalarKind<T>> CaptureOutputDecimal<T>(
byte precision,
byte scale,
[CallerArgumentExpression(nameof(value))] string? name = null)
{
CaptureSource<decimal?> source = Captures.Decimal(name, precision, scale);
BoundCall<ScalarKind<T>> captured = WithCapture(call, source);
value = new(source);
return captured;
}
=> WithCapture(
call,
Captures.Decimal(name, precision, scale),
out value);

/// <summary>
/// Reads the stored procedure's return code, converted to
Expand All @@ -551,10 +533,5 @@ public static BoundCall<ScalarKind<T>> CaptureOutputDecimal<T>(
public static BoundCall<ScalarKind<T>> CaptureReturn<T, TValue>(
this BoundCall<ScalarKind<T>> call,
out DbCapture<TValue> returnCode)
{
CaptureSource<TValue> source = Captures.Return<TValue>();
BoundCall<ScalarKind<T>> captured = WithCapture(call, source);
returnCode = new(source);
return captured;
}
=> WithCapture(call, Captures.Return<TValue>(), out returnCode);
}
Loading