MCPcopy Create free account
hub / github.com/BaseXdb/basex / opt

Method opt

basex-core/src/main/java/org/basex/query/func/fn/FnCount.java:38–57  ·  view source on GitHub ↗
(final CompileContext cc)

Source from the content-addressed store, hash-verified

36 }
37
38 @Override
39 protected Expr opt(final CompileContext cc) throws QueryException {
40 // return static result size
41 final Expr input = arg(0);
42 final long size = input.size();
43 if(size >= 0 && !input.has(Flag.NDT)) return Itr.get(size);
44
45 // count(map:keys(E)) → map:size(E)
46 if(_MAP_KEYS.is(input))
47 return cc.function(_MAP_SIZE, info, input.args());
48 // count(util:array-members(E)) → array:size(E)
49 if(_ARRAY_MEMBERS.is(input))
50 return cc.function(_ARRAY_SIZE, info, input.args());
51 // count(string-to-codepoints(E)) → string-length(E)
52 // count(characters(E)) → string-length(E)
53 if(STRING_TO_CODEPOINTS.is(input) || CHARACTERS.is(input))
54 return cc.function(STRING_LENGTH, info, input.args());
55
56 return embed(cc, true);
57 }
58
59 @Override
60 public Expr simplifyFor(final Simplify mode, final CompileContext cc) throws QueryException {

Callers

nothing calls this directly

Calls 8

sizeMethod · 0.95
hasMethod · 0.95
getMethod · 0.95
argsMethod · 0.95
embedMethod · 0.80
isMethod · 0.65
argMethod · 0.45
functionMethod · 0.45

Tested by

no test coverage detected