Skip to content
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

[Dubbo-3625] Add constant 'MIN_PATH_ARRAY_LENGTH' #3680

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ public void dataChanged(String path, Object value, EventType eventType) {
// TODO We limit the notification of config changes to a specific path level, for example
// /dubbo/config/service/configurators, other config changes not in this level will not get notified,
// say /dubbo/config/dubbo.properties
if (path.split("/").length >= 5) {
final int MIN_PATH_ARRAY_LENGTH = 5;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to make it static.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to be local, because it is only used in one method.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it is not. As a local constant, it will be allocated every time the method is invoked. I don't think it should be local.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I make an experiment.

public class Test {
    private static final int CLZ_FIELD = 65535;
    public static void main(String[] args) {
        final int localVariable = 65536;
        System.out.println(localVariable);
        System.out.println(CLZ_FIELD);
    }
}

After decompilation, I got

public static void main(java.lang.String[]);
  Code:
     0: ldc           #2                  // int 65536
     2: istore_1
     3: getstatic     #3                  // Field java/lang/System.out:Ljava/io/PrintStream;
     6: ldc           #2                  // int 65536
     8: invokevirtual #4                  // Method java/io/PrintStream.println:(I)V
    11: getstatic     #3                  // Field java/lang/System.out:Ljava/io/PrintStream;
    14: ldc           #6                  // int 65535
    16: invokevirtual #4                  // Method java/io/PrintStream.println:(I)V
    19: return

Every time the local constant need one more step ('0: ldc #2') and one more stack space than static constant.
So you are right, I will make it static.

if (path.split("/").length >= MIN_PATH_ARRAY_LENGTH) {
String key = pathToKey(path);
ConfigChangeType changeType;
switch (eventType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,7 @@ private void doReceived(Response res) {
lock.lock();
try {
response = res;
if (done != null) {
done.signal();
}
done.signalAll();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, this change is irrelevant. And is addressed in #3681 . Please rebase with the master and send the pull request again.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK,I will send the pull request again.

} finally {
lock.unlock();
}
Expand Down