ballerina-lang
ballerina-lang copied to clipboard
[Refactoring] Replace "Stack" with "Deque".
Purpose
Early classes of the Java API, such as Vector, Hashtable and StringBuffer, were synchronized to make them thread-safe. However, synchronization has a significant negative impact on performance, even when using these collections from a single thread.
It is often best to use their non-synchronized counterparts:
- ArrayList or LinkedList instead of Vector
- Deque instead of Stack
- HashMap instead of Hashtable
- StringBuilder instead of StringBuffer
Even when used in synchronized contexts, you should think twice before using their synchronized counterparts, since their usage can be costly. If you are confident the usage is legitimate, you can safely ignore this warning.
https://sonarcloud.io/organizations/ballerina-platform/rules?open=java%3AS1149&rule_key=java%3AS1149
Since for Stacks the Head of the Stack is the last element and for Deque it is the first, I needed to change up the iteration order when iterating over the Stack/Deque. Also, for Stck add() and push() are equivalent, since they push to the end of the List, but for Deque, push() is inserting in the front, which changes the semantics.
Check List
- [x] Read the Contributing Guide
- [ ] Updated Change Log
- [ ] Checked Tooling Support (#<Issue Number>)
- [ ] Added necessary tests
- [ ] Unit Tests
- [ ] Spec Conformance Tests
- [ ] Integration Tests
- [ ] Ballerina By Example Tests
- [ ] Increased Test Coverage
- [ ] Added necessary documentation
- [ ] API documentation
- [ ] Module documentation in Module.md files
- [ ] Ballerina By Examples
- [ ]
This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the stale label is removed or commented.
Codecov Report
Attention: Patch coverage is 85.08772% with 17 lines in your changes missing coverage. Please review.
Project coverage is 77.35%. Comparing base (
2f331d4) to head (13f8f45). Report is 436 commits behind head on master.
Additional details and impacted files
@@ Coverage Diff @@
## master #42914 +/- ##
============================================
+ Coverage 77.30% 77.35% +0.05%
- Complexity 58532 58580 +48
============================================
Files 3460 3459 -1
Lines 220074 220088 +14
Branches 28911 28913 +2
============================================
+ Hits 170125 170256 +131
+ Misses 40544 40416 -128
- Partials 9405 9416 +11
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the stale label is removed or commented.
Fixed review comments in c96a7e9
This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the stale label is removed or commented.
This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the stale label is removed or commented.
@Shadow-Devil Some stdlib levels seem to be failing. Shall we retrigger and check?
Error log:
Compiling source
graphql/starwars:0.1.0
ERROR [service.bal:(18:1,18:21)] cannot resolve module 'xlibb/pubsub'
ERROR [service.bal:(47:19,47:32)] undefined module 'pubsub'
ERROR [service.bal:(47:19,47:32)] unknown type 'PubSub'
error: compilation contains errors
Author identity unknown
Example 'starwars' Build failed: Process 'command 'sh'' finished with non-zero exit value 1
I don't think this is related to this PR but something with the graphql tests.
Error log:
Compiling source graphql/starwars:0.1.0 ERROR [service.bal:(18:1,18:21)] cannot resolve module 'xlibb/pubsub' ERROR [service.bal:(47:19,47:32)] undefined module 'pubsub' ERROR [service.bal:(47:19,47:32)] unknown type 'PubSub' error: compilation contains errors Author identity unknown Example 'starwars' Build failed: Process 'command 'sh'' finished with non-zero exit value 1I don't think this is related to this PR but something with the graphql tests.
Retriggered and build passed :)