[
https://issues.apache.org/jira/browse/DERBY-2191?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12468242
]
Øystein Grøvlen commented on DERBY-2191:
----------------------------------------
The javadoc for anySetBit says that it will "return the bit number of
a bit that is set". If I understand the implementation correctly, it
will always return the first bit that is set. Looking at some of the
usages of anySetBit, it seems like this behavior is also assumed. For
example, it seems to be used to iterate over all set bits of the bit
set (e.g., BasicNoPutResultSetImpl.getCompactRow()).
It think it would be a good idea to give this function a more
descriptive name or at least change the javadoc to reflect the assumed
and implemented behavior.
I also seems that at least for one usage of anySetBit(), returning the
first set bit, is the least optimal (see
ResultColumnList.generateHolderMethod(), which tries to find the
maximum column number for which the corresponding bit is set).
For firstSet(), you can reduce the average number of comparisons by
doing binary search, something like:
if ((v & 0xf0) != 0) {
if ((v & 0xc0) != 0) {
if ((v & 0x80) != 0) {
return 0;
} else {
return 0x1;
}
} else {
if ((v & 0x20) != 0) {
return 0x2;
}
else {
return 0x3;
}
}
else {
if ((v & 0xc) != 0) {
...
However, I cannot guarantee that a smaller number of comparisons will
give better performance. I have no idea what impact this has with
respect to how the processsor does instruction preloading etc.
> Cleanup of FormatableBitSet
> ---------------------------
>
> Key: DERBY-2191
> URL: https://issues.apache.org/jira/browse/DERBY-2191
> Project: Derby
> Issue Type: Improvement
> Components: Miscellaneous
> Affects Versions: 10.2.1.6
> Reporter: Dyre Tjeldvoll
> Assigned To: Dyre Tjeldvoll
> Priority: Trivial
> Fix For: 10.3.0.0
>
> Attachments: anysetbit.v1.diff, anysetbit.v1.stat, bitops.v1.diff,
> bitops.v1.stat, bitops.v2.diff, bitops.v2.stat, bitops.v3.diff,
> bitopt.v1.diff, bitopt.v1.stat, bitopt.v2.diff, boundarycheck.v1.diff,
> boundarycheck.v1.stat, cleanup2191.diff, cleanup2191.stat, deadcode.v1.diff,
> deadcode.v2.diff, fbstst.v1.diff, fbstst.v1.stat, FormatableBitSetTest.java,
> numbitsset.v1.diff, numbitsset.v1.stat, unusedmethods.v1.diff,
> unusedmethods.v1.stat, valuenotnull.v1.diff, valuenotnull.v1.stat
>
>
> The implementation of FormatableBitSet could be streamlined. Dead code can be
> removed and the implementation of some methods can be simplified.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.