[Win32] Simplify and fix Region class#3224
Open
HeikoKlare wants to merge 1 commit intoeclipse-platform:masterfrom
Open
[Win32] Simplify and fix Region class#3224HeikoKlare wants to merge 1 commit intoeclipse-platform:masterfrom
HeikoKlare wants to merge 1 commit intoeclipse-platform:masterfrom
Conversation
Contributor
Contributor
|
I did not check in the code (sorry)but would that cleanup also make sense for Linux ans Mac Implementation or why is this "only" done for windows? |
Contributor
Author
|
The |
- Fix toString() missing closing brace (output was malformed) - Use computeIfAbsent() in getRegionHandle() instead of manual containsKey/put/get - Move RECT allocation inside isEmpty() lambda where it belongs - Replace getBounds() block lambda with expression lambda - Eliminate duplicate create/combine/delete patterns in OperationWithRectangle (3 methods -> combineWithRectInPixels) and OperationWithArray (2 methods -> combineWithPolyInPixels) - Convert OperationWithRegion block lambdas to expression lambdas - Remove redundant public modifiers on constructors of private inner classes OperationWithArray and OperationWithPoint
7ce8659 to
68ef8c8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This change cleans up the win32
Region.javaimplementation by removing duplication, fixing a formatting bug, and applying idiomatic Java patterns throughout.Bug fix
toString()produced malformed output: The method opened a{but never closed it, producing strings likeRegion {handle(zoom:100)instead ofRegion {handle(zoom:100)}. This made debugging harder and was inconsistent with the disposed-region case which does close its braces.Simplifications
getRegionHandle(int): Replaced the manualcontainsKey/put/gettriple withMap.computeIfAbsent, which is the idiomatic Java way to lazily populate a map and avoids two redundant lookups.getBounds(): A block lambda containing only a singlereturnwas converted to an expression lambda.isEmpty(): TheRECTobject was allocated before the lambda, even though it is only needed inside it. Moved it inside the lambda to keep allocation and use co-located and to avoid capturing a mutable object across a closure boundary unnecessarily.Eliminated code duplication
OperationWithRectangle: The three methodsaddInPixels,subtractInPixels, andintersectInPixelswere virtually identical — each created a rect region, calledCombineRgnwith a different mode constant, then deleted the region. These were replaced by a singlecombineWithRectInPixels(handle, x, y, w, h, mode)helper, reducing ~15 lines to ~5.OperationWithArray: The same pattern applied toaddInPixelsandsubtractInPixels, collapsed intocombineWithPolyInPixels(handle, pointArray, mode).OperationWithRegion: Three block lambdas each containing a singlereturn OS.CombineRgn(...)call were converted to expression lambdas, removing the syntactic noise.Access modifiers
publicfrom the constructors ofOperationWithArrayandOperationWithPoint. Both classes are declaredprivate static, sopublicon their constructors has no semantic effect and is misleading.Test plan
Region-related JUnit tests pass without modificationtoString()output now includes the closing}for non-disposed regions