ballerina-lang icon indicating copy to clipboard operation
ballerina-lang copied to clipboard

[Refactoring] Replace "Stack" with "Deque".

Open f-schnabel opened this issue 1 year ago • 2 comments
trafficstars

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
    • [ ]

f-schnabel avatar Jun 12 '24 21:06 f-schnabel

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.

github-actions[bot] avatar Jul 01 '24 19:07 github-actions[bot]

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.

Files with missing lines Patch % Lines
...alang/compiler/semantics/analyzer/SymbolEnter.java 0.00% 6 Missing :warning:
.../runtime/transactions/TransactionLocalContext.java 0.00% 5 Missing :warning:
...lang/compiler/semantics/analyzer/CodeAnalyzer.java 77.77% 0 Missing and 2 partials :warning:
...ina/shell/cli/jline/parser/ParserStateMachine.java 80.00% 0 Missing and 1 partial :warning:
...allerinalang/compiler/parser/BLangNodeBuilder.java 80.00% 0 Missing and 1 partial :warning:
...piler/semantics/analyzer/ReachabilityAnalyzer.java 91.66% 0 Missing and 1 partial :warning:
...lang/compiler/semantics/analyzer/TypeResolver.java 87.50% 0 Missing and 1 partial :warning:
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.

codecov[bot] avatar Jul 02 '24 10:07 codecov[bot]

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.

github-actions[bot] avatar Jul 20 '24 19:07 github-actions[bot]

Fixed review comments in c96a7e9

f-schnabel avatar Jul 22 '24 13:07 f-schnabel

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.

github-actions[bot] avatar Aug 18 '24 19:08 github-actions[bot]

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.

github-actions[bot] avatar Sep 06 '24 19:09 github-actions[bot]

@Shadow-Devil Some stdlib levels seem to be failing. Shall we retrigger and check?

Dilhasha avatar Sep 12 '24 05:09 Dilhasha

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.

f-schnabel avatar Sep 12 '24 11:09 f-schnabel

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.

Retriggered and build passed :)

gimantha avatar Sep 14 '24 03:09 gimantha