You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Once #3570 merges, we can and should change more or less all Vector iteration in our libraries to use iterator or stream methods, rather than looping on get calls. This is potentially far more efficient for some Vector types, especially those downstream of a groupBy, aggBy with Group, updateBy with RollingGroup, or rangeJoin with Group.
For example:
This code in Basic.ftl:
static public <T> long countObj(ObjectVector<T> values) {
if (values == null) {
return NULL_LONG;
}
final long n = values.size();
long count = 0;
for (long i = 0; i < n; i++) {
T c = values.get(i);
if (!isNull(c)) {
count++;
}
}
return count;
}
should be:
static public <T> long countObj(ObjectVector<T> values) {
if (values == null) {
return NULL_LONG;
}
if (values.isEmpty()) {
return 0;
}
long count = 0;
for (final Iterator<T> vi = values.iterator(); vi.hasNext(); ){
final T c = vi.next();
if (!isNull(c)) {
count++;
}
}
return count;
}
We could also write it like this, but it's probably worse:
static public <T> long countObj(ObjectVector<T> values) {
if (values == null) {
return NULL_LONG;
}
if (values.isEmpty()) {
return 0;
}
return values.iterator().stream().filter(c -> !isNull(c)).count();
}
A related change we should also make: Avoid using Vectorget when array access will do:
This code in Basic.ftl:
static public <T> T[] replaceIfNull(ObjectVector<T> values, T replacement) {
final int n = values.intSize("replaceIfNull");
T[] result = values.toArray();
for (int i = 0; i < n; i++) {
result[i] = replaceIfNull(values.get(i), replacement);
}
return result;
}
should be:
static public <T> T[] replaceIfNull(ObjectVector<T> values, T replacement) {
final int n = values.intSize("replaceIfNull");
T[] result = values.toArray();
for (int i = 0; i < n; i++) {
result[i] = replaceIfNull(result[i], replacement);
}
return result;
}
The text was updated successfully, but these errors were encountered:
Once #3570 merges, we can and should change more or less all Vector iteration in our libraries to use
iterator
orstream
methods, rather than looping onget
calls. This is potentially far more efficient for someVector
types, especially those downstream of agroupBy
,aggBy
withGroup
,updateBy
withRollingGroup
, orrangeJoin
withGroup
.For example:
This code in
Basic.ftl
:should be:
We could also write it like this, but it's probably worse:
A related change we should also make: Avoid using
Vector
get
when array access will do:This code in
Basic.ftl
:should be:
The text was updated successfully, but these errors were encountered: