mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-09 20:17:41 +00:00
support opaque kinds
This commit is contained in:
parent
0a4e863373
commit
953fbaca48
@ -33,7 +33,7 @@ type CIDR struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
CIDRType = cel.ObjectType("net.CIDR")
|
CIDRType = cel.OpaqueType("net.CIDR")
|
||||||
)
|
)
|
||||||
|
|
||||||
// ConvertToNative implements ref.Val.ConvertToNative.
|
// ConvertToNative implements ref.Val.ConvertToNative.
|
||||||
|
@ -33,7 +33,7 @@ type IP struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
IPType = cel.ObjectType("net.IP")
|
IPType = cel.OpaqueType("net.IP")
|
||||||
)
|
)
|
||||||
|
|
||||||
// ConvertToNative implements ref.Val.ConvertToNative.
|
// ConvertToNative implements ref.Val.ConvertToNative.
|
||||||
|
@ -498,19 +498,27 @@ func (l *CostEstimator) EstimateCallCost(function, overloadId string, target *ch
|
|||||||
rhs := args[1]
|
rhs := args[1]
|
||||||
if lhs.Type().Equal(rhs.Type()) == types.True {
|
if lhs.Type().Equal(rhs.Type()) == types.True {
|
||||||
t := lhs.Type()
|
t := lhs.Type()
|
||||||
switch t {
|
if t.Kind() == types.OpaqueKind {
|
||||||
case cel.IPType, cel.CIDRType, cel.QuantityType: // O(1) cost equality checks
|
switch t.TypeName() {
|
||||||
return &checker.CallEstimate{CostEstimate: checker.CostEstimate{Min: 1, Max: 1}}
|
case cel.IPType.TypeName(), cel.CIDRType.TypeName():
|
||||||
case cel.FormatType:
|
return &checker.CallEstimate{CostEstimate: checker.CostEstimate{Min: 1, Max: 1}}
|
||||||
return &checker.CallEstimate{CostEstimate: checker.CostEstimate{Min: 1, Max: cel.MaxFormatSize}.MultiplyByCostFactor(common.StringTraversalCostFactor)}
|
}
|
||||||
case cel.URLType:
|
}
|
||||||
size := checker.SizeEstimate{Min: 1, Max: 1}
|
if t.Kind() == types.StructKind {
|
||||||
rhSize := rhs.ComputedSize()
|
switch t {
|
||||||
lhSize := rhs.ComputedSize()
|
case cel.QuantityType: // O(1) cost equality checks
|
||||||
if rhSize != nil && lhSize != nil {
|
return &checker.CallEstimate{CostEstimate: checker.CostEstimate{Min: 1, Max: 1}}
|
||||||
size = rhSize.Union(*lhSize)
|
case cel.FormatType:
|
||||||
|
return &checker.CallEstimate{CostEstimate: checker.CostEstimate{Min: 1, Max: cel.MaxFormatSize}.MultiplyByCostFactor(common.StringTraversalCostFactor)}
|
||||||
|
case cel.URLType:
|
||||||
|
size := checker.SizeEstimate{Min: 1, Max: 1}
|
||||||
|
rhSize := rhs.ComputedSize()
|
||||||
|
lhSize := rhs.ComputedSize()
|
||||||
|
if rhSize != nil && lhSize != nil {
|
||||||
|
size = rhSize.Union(*lhSize)
|
||||||
|
}
|
||||||
|
return &checker.CallEstimate{CostEstimate: checker.CostEstimate{Min: 1, Max: size.Max}.MultiplyByCostFactor(common.StringTraversalCostFactor)}
|
||||||
}
|
}
|
||||||
return &checker.CallEstimate{CostEstimate: checker.CostEstimate{Min: 1, Max: size.Max}.MultiplyByCostFactor(common.StringTraversalCostFactor)}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user