This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 268746 - Replace EnumSet.of() with EnumSet.noneOf().add() in UsagesData.java
Summary: Replace EnumSet.of() with EnumSet.noneOf().add() in UsagesData.java
Status: NEW
Alias: None
Product: java
Classification: Unclassified
Component: Platform (show other bugs)
Version: Dev
Hardware: PC Windows 7
: P3 normal (vote)
Assignee: Tomas Zezula
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-10-30 14:09 UTC by NukemBy
Modified: 2016-10-30 14:09 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
EnumSet.of.png (51.51 KB, image/png)
2016-10-30 14:09 UTC, NukemBy
Details

Note You need to log in before you can comment on or make changes to this bug.
Description NukemBy 2016-10-30 14:09:34 UTC
Created attachment 162690 [details]
EnumSet.of.png

It appears that there is huge performance difference between EnumSet.of() with EnumSet.noneOf().add() - the first one is roughly 3-4 times slower (because of inner call to Class.getSuperClass()) and in the amount of iterations for UsagesData.addUsage() this is rather significant difference in overall time. Attached is the 'proof-link' for another similar case in another module.

Required change is rather minor

    void addUsage(
            @NonNull final T className,
            @NonNull final ClassIndexImpl.UsageType type) {
        Set<ClassIndexImpl.UsageType> usageType = usages.get (className);
        if (usageType == null) {
            usageType = EnumSet.of(type);
            usages.put (className, usageType);
        } else {
            usageType.add (type);
        }
    }

-->

    void addUsage(
            @NonNull final T className,
            @NonNull final ClassIndexImpl.UsageType type) {
        Set<ClassIndexImpl.UsageType> usageType = usages.get (className);
        if (usageType == null) {
            usageType = EnumSet.noneOf(ClassIndexImpl.UsageType.class);
            usages.put (className, usageType);
        }
        usageType.add (type);
    }