-
Enhancement
-
Resolution: Fixed
-
P4
-
None
-
b07
From compiler-dev
When I read the code at `jdk.compiler/com.sun.tools.javac.parser.Tokens` and ``jdk.compiler/com.sun.tools.javac.util.Names`, I find a point which can be possibly improved.
The constructor of the class `Tokens` invokes `Names.instance(context)` to initialize `Names` which would initialize many unrelated names. Then, this constructor uses the method `enterKeyword` to initialize the names about `TokenKind` and to set `maxKey`. Because `Names.instance(context)` initializes many unrelated names, the `Name.index` becomes very large so that the `maxKey` also becomes very large. Then, the constructor creates an array `key` by using the code `key = new TokenKind[maxKey+1]`. We can identify that the variable `key` is unnecessary to be so large.
I would like to initialize the related names, which are about `TokenKind`, at the beginning of the constructor of the class `Names` to improve the code. The complete patch is shown at the end of this email.
When using the code of the master branch, the length of the array `Tokens.key` is 4280. When using my patch, the length of the array `Tokens.key` is 383. The improvement is obvious.
When I read the code at `jdk.compiler/com.sun.tools.javac.parser.Tokens` and ``jdk.compiler/com.sun.tools.javac.util.Names`, I find a point which can be possibly improved.
The constructor of the class `Tokens` invokes `Names.instance(context)` to initialize `Names` which would initialize many unrelated names. Then, this constructor uses the method `enterKeyword` to initialize the names about `TokenKind` and to set `maxKey`. Because `Names.instance(context)` initializes many unrelated names, the `Name.index` becomes very large so that the `maxKey` also becomes very large. Then, the constructor creates an array `key` by using the code `key = new TokenKind[maxKey+1]`. We can identify that the variable `key` is unnecessary to be so large.
I would like to initialize the related names, which are about `TokenKind`, at the beginning of the constructor of the class `Names` to improve the code. The complete patch is shown at the end of this email.
When using the code of the master branch, the length of the array `Tokens.key` is 4280. When using my patch, the length of the array `Tokens.key` is 383. The improvement is obvious.