-
Notifications
You must be signed in to change notification settings - Fork 335
Encapsulating currentSize in ValidityBuffer
#14665
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
JaroslavTulach
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
James, here is description of the refactoring motivations, decisions and doubts that made me turn this PR into a draft. Please take a look. Probably also take it over, as I doubt I understand the implications of the change.
| permits DoubleBuilder, LongBuilder, DateBuilder { | ||
| private BitSet validityMap; | ||
| int currentSize; | ||
| private int currentSize; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- encapsulating this
currentSizefield is the main goal of this PR, @jdunkerley
| try { | ||
| appendAt(currentSize, o); | ||
| this.setValid(currentSize); | ||
| currentSize++; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- however, if
currentSizeisprivate, then - these manipulations of the field must be in
ValidityBuffer - hence moving
appendhere - it is not a bad refactoring as most of the
appendimplementations are copies of themselves - but of course,
ValidityBufferonly handles null values by itself - hence we need a seam - e.g.
appendAt
| resize(desiredCapacity); | ||
| } | ||
|
|
||
| protected abstract void appendAt(int index, Object value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- this is the seam for subclasses to hook in
- and somehow store the provided
valueinto their storage (e.g.IntBuffer, etc.)
| } | ||
|
|
||
| private int currentSize() { | ||
| return Math.toIntExact(getCurrentSize()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- off topic, but:
- the fact that we use
intas index, but returnlongfromgetCurrentSize()is very annoying - I assume the original intention was to allow huge storages, but
- when the builders use
inteverywhere else, it just stays in the way- as the proliferation of various
Math.toIntExactor(int)casts demonstrates
- as the proliferation of various
- wouldn't it be easier to make it
int getCurrentSize(), @jdunkerley?
| ensureSpaceToAppend(); | ||
| setValid(currentSize); | ||
| data.put(currentSize++, value); | ||
| append(value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- this is the place where I started to doubt I am doing the right refactoring
DoubleBuildercannot accesscurrentSizedirectly- as the goal is to encapsulate all the
currentSizemanipulation inValidityBuffer
- as the goal is to encapsulate all the
- so the only thing it can do is to delegate to
ValidityBuffer.appendand wait for aappendAtcallback - but that all renders all these
appendDouble,appendLonguseless...
Pull Request Description
LocalDatein off-heapIntBuffer#14652 for your consideration @jdunkerleyValidityBufferis responsible for handling null valuescurrentSizefieldcurrentSizefieldprivate, but ...appendLong,appendDouble& co.Important Notes
Checklist
Please ensure that the following checklist has been satisfied before submitting the PR:
Java,