replace PipelineOp[] with short[]
This commit is contained in:
parent
a53f7db25e
commit
789d2df6e4
5 changed files with 43 additions and 68 deletions
|
@ -398,7 +398,7 @@ final class RpcState<VatId> {
|
|||
LOGGER.fine(() -> this.toString() + ": > BOOTSTRAP question=" + question.id);
|
||||
message.send();
|
||||
|
||||
return pipeline.getPipelinedCap(new PipelineOp[0]);
|
||||
return pipeline.getPipelinedCap(new short[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1534,7 +1534,7 @@ final class RpcState<VatId> {
|
|||
private RpcResponse resolved;
|
||||
private Throwable broken;
|
||||
|
||||
private final HashMap<List<PipelineOp>, ClientHook> clientMap = new HashMap<>();
|
||||
private final HashMap<List<Short>, ClientHook> clientMap = new HashMap<>();
|
||||
private final CompletableFuture<RpcResponse> redirectLater;
|
||||
private final CompletableFuture<RpcResponse> resolveSelf;
|
||||
|
||||
|
@ -1566,9 +1566,11 @@ final class RpcState<VatId> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ClientHook getPipelinedCap(PipelineOp[] ops) {
|
||||
// TODO avoid conversion to/from ArrayList?
|
||||
var key = new ArrayList<>(Arrays.asList(ops));
|
||||
public ClientHook getPipelinedCap(short[] ops) {
|
||||
var key = new ArrayList<Short>(ops.length);
|
||||
for (short op: ops) {
|
||||
key.add(op);
|
||||
}
|
||||
|
||||
return this.clientMap.computeIfAbsent(key, k -> {
|
||||
return switch (state) {
|
||||
|
@ -2003,11 +2005,11 @@ final class RpcState<VatId> {
|
|||
private class PipelineClient extends RpcClient {
|
||||
|
||||
private final QuestionRef questionRef;
|
||||
private final PipelineOp[] ops;
|
||||
private final short[] ops;
|
||||
|
||||
PipelineClient(QuestionRef questionRef, PipelineOp[] ops) {
|
||||
PipelineClient(QuestionRef questionRef, short[] ops) {
|
||||
this.questionRef = questionRef;
|
||||
this.ops = ops;
|
||||
this.ops = ops.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -2037,34 +2039,35 @@ final class RpcState<VatId> {
|
|||
}
|
||||
}
|
||||
|
||||
static void FromPipelineOps(PipelineOp[] ops, RpcProtocol.PromisedAnswer.Builder builder) {
|
||||
static void FromPipelineOps(short[] ops, RpcProtocol.PromisedAnswer.Builder builder) {
|
||||
var transforms = builder.initTransform(ops.length);
|
||||
for (int ii = 0; ii < ops.length; ++ii) {
|
||||
var transform = transforms.get(ii);
|
||||
switch (ops[ii].type) {
|
||||
case NOOP -> transform.setNoop(null);
|
||||
case GET_POINTER_FIELD -> transform.setGetPointerField(ops[ii].pointerIndex);
|
||||
var pointerIndex = ops[ii];
|
||||
if (pointerIndex < 0) {
|
||||
transform.setNoop(null);
|
||||
}
|
||||
else {
|
||||
transform.setGetPointerField(pointerIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static PipelineOp[] ToPipelineOps(RpcProtocol.PromisedAnswer.Reader reader) {
|
||||
static short[] ToPipelineOps(RpcProtocol.PromisedAnswer.Reader reader) {
|
||||
var transforms = reader.getTransform();
|
||||
var ops = new PipelineOp[transforms.size()];
|
||||
var ops = new short[transforms.size()];
|
||||
for (int ii = 0; ii < ops.length; ++ii) {
|
||||
var transform = transforms.get(ii);
|
||||
switch (transform.which()) {
|
||||
case NOOP:
|
||||
ops[ii] = PipelineOp.Noop(); // TODO null?
|
||||
ops[ii] = -1;
|
||||
break;
|
||||
case GET_POINTER_FIELD:
|
||||
ops[ii] = PipelineOp.PointerField(transform.getGetPointerField());
|
||||
ops[ii] = transform.getGetPointerField();
|
||||
break;
|
||||
default:
|
||||
// TODO improve error handling here
|
||||
// Unsupported pipeline ops
|
||||
case _NOT_IN_SCHEMA:
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
return ops;
|
||||
}
|
||||
|
|
|
@ -80,18 +80,13 @@ public final class AnyPointer {
|
|||
return factory.fromPointerReader(this.segment, this.capTable, this.pointer, this.nestingLimit);
|
||||
}
|
||||
|
||||
public final ClientHook getPipelinedCap(PipelineOp[] ops) {
|
||||
public final ClientHook getPipelinedCap(short[] ops) {
|
||||
AnyPointer.Reader any = this;
|
||||
|
||||
for (var op: ops) {
|
||||
switch (op.type) {
|
||||
case NOOP:
|
||||
break;
|
||||
case GET_POINTER_FIELD:
|
||||
var index = op.pointerIndex;
|
||||
var reader = WireHelpers.readStructPointer(any.segment, any.capTable, any.pointer, null, 0, any.nestingLimit);
|
||||
any = reader._getPointerField(AnyPointer.factory, op.pointerIndex);
|
||||
break;
|
||||
for (var pointerIndex: ops) {
|
||||
if (pointerIndex >= 0) {
|
||||
var reader = WireHelpers.readStructPointer(any.segment, any.capTable, any.pointer, null, 0, any.nestingLimit);
|
||||
any = reader._getPointerField(AnyPointer.factory, pointerIndex);
|
||||
}
|
||||
}
|
||||
return WireHelpers.readCapabilityPointer(any.segment, any.capTable, any.pointer, 0);
|
||||
|
@ -151,13 +146,13 @@ public final class AnyPointer {
|
|||
implements org.capnproto.Pipeline {
|
||||
|
||||
final PipelineHook hook;
|
||||
private final PipelineOp[] ops;
|
||||
private final short[] ops;
|
||||
|
||||
public Pipeline(PipelineHook hook) {
|
||||
this(hook, new PipelineOp[0]);
|
||||
this(hook, new short[0]);
|
||||
}
|
||||
|
||||
Pipeline(PipelineHook hook, PipelineOp[] ops) {
|
||||
Pipeline(PipelineHook hook, short[] ops) {
|
||||
this.hook = hook;
|
||||
this.ops = ops;
|
||||
}
|
||||
|
@ -181,9 +176,9 @@ public final class AnyPointer {
|
|||
}
|
||||
|
||||
public Pipeline getPointerField(short pointerIndex) {
|
||||
var newOps = new PipelineOp[this.ops.length + 1];
|
||||
var newOps = new short[this.ops.length + 1];
|
||||
System.arraycopy(this.ops, 0, newOps, 0, this.ops.length);
|
||||
newOps[this.ops.length] = PipelineOp.PointerField(pointerIndex);
|
||||
newOps[this.ops.length] = pointerIndex;
|
||||
return new Pipeline(this.hook, newOps);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -465,7 +465,7 @@ public final class Capability {
|
|||
}
|
||||
|
||||
@Override
|
||||
public final ClientHook getPipelinedCap(PipelineOp[] ops) {
|
||||
public final ClientHook getPipelinedCap(short[] ops) {
|
||||
return this.results.getPipelinedCap(ops);
|
||||
}
|
||||
}
|
||||
|
@ -689,7 +689,7 @@ public final class Capability {
|
|||
|
||||
private final CompletableFuture<PipelineHook> promise;
|
||||
PipelineHook redirect;
|
||||
private final Map<List<PipelineOp>, ClientHook> clientMap = new HashMap<>();
|
||||
private final Map<List<Short>, ClientHook> clientMap = new HashMap<>();
|
||||
|
||||
QueuedPipeline(CompletableFuture<PipelineHook> promise) {
|
||||
this.promise = promise.whenComplete((pipeline, exc) -> {
|
||||
|
@ -700,11 +700,16 @@ public final class Capability {
|
|||
}
|
||||
|
||||
@Override
|
||||
public final ClientHook getPipelinedCap(PipelineOp[] ops) {
|
||||
public final ClientHook getPipelinedCap(short[] ops) {
|
||||
if (redirect != null) {
|
||||
return redirect.getPipelinedCap(ops);
|
||||
}
|
||||
var key = Arrays.asList(ops);
|
||||
|
||||
var key = new ArrayList<Short>(ops.length);
|
||||
for (short op: ops) {
|
||||
key.add(op);
|
||||
}
|
||||
|
||||
return this.clientMap.computeIfAbsent(key,
|
||||
k -> new QueuedClient(this.promise.thenApply(
|
||||
pipeline -> pipeline.getPipelinedCap(ops))));
|
||||
|
|
|
@ -2,7 +2,7 @@ package org.capnproto;
|
|||
|
||||
public interface PipelineHook {
|
||||
|
||||
ClientHook getPipelinedCap(PipelineOp[] ops);
|
||||
ClientHook getPipelinedCap(short[] ops);
|
||||
|
||||
default void cancel(Throwable exc) {
|
||||
}
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
package org.capnproto;
|
||||
|
||||
final class PipelineOp {
|
||||
|
||||
// TODO just use array of Short?
|
||||
|
||||
enum Type {
|
||||
NOOP,
|
||||
GET_POINTER_FIELD
|
||||
}
|
||||
|
||||
final PipelineOp.Type type;
|
||||
final short pointerIndex;
|
||||
|
||||
private PipelineOp(PipelineOp.Type type, short pointerIndex) {
|
||||
this.type = type;
|
||||
this.pointerIndex = pointerIndex;
|
||||
}
|
||||
|
||||
static PipelineOp Noop() {
|
||||
return new PipelineOp(Type.NOOP, (short) 0);
|
||||
}
|
||||
|
||||
static PipelineOp PointerField(short pointerIndex) {
|
||||
return new PipelineOp(Type.GET_POINTER_FIELD, pointerIndex);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue