Skip to content

Method invokes inefficient Number constructor #1245

Closed

Description

@hqq2023623

JavaDeserializer#getParamArg

1

for values that between -128 ~ 127 , autoboxing or call valueOf() is more efficient than using consctrutor , and use less memory .

reference blog :
http://blog.csdn.net/qq_27093465/article/details/52473649

ways to change : change to autoboxing or Xxx.valueOf(0);

below is the change :

protected static Object getParamArg(Class cl) {
    if (!cl.isPrimitive())
        return null;
    else if (boolean.class.equals(cl))
        return Boolean.FALSE;
    else if (byte.class.equals(cl))
        return 0;
    else if (short.class.equals(cl))
        return 0;
    else if (char.class.equals(cl))
        return 0;
    else if (int.class.equals(cl))
        return 0;
    else if (long.class.equals(cl))
        return 0L;
    else if (float.class.equals(cl))
        return 0F;
    else if (double.class.equals(cl))
        return 0D;
    else
        throw new UnsupportedOperationException();
}

Activity

  1. added this to the 2.6.1 milestone on Jan 23, 2018
  2. added a commit that references this issue on Jan 23, 2018
    a5b4a3f
  3. chickenlj commented on Feb 17, 2018

    @chickenlj
    Contributor

    Can you please create a PR?

  4. modified the milestones: 2.6.1, 2.6.2 on Feb 17, 2018
  5. added a commit that references this issue on Feb 19, 2018
    1b7fc08
  6. zonghaishang commented on Feb 19, 2018

    @zonghaishang
    Member

    How to creat patch file ?

  7. zonghaishang commented on Feb 19, 2018

    @zonghaishang
    Member

    How to create patch files ?

  8. added a commit that references this issue on Feb 24, 2018
    ddb677b
  9. added 3 commits that reference this issue on Feb 26, 2018
    0d7dfaa
    125e6a1
    a3b8d73
  10. removed this from the 2.6.2 milestone on Apr 24, 2018
  11. chickenlj commented on Apr 24, 2018

    @chickenlj
    Contributor

    Sorry, this change seems to have some problems. Refer your PR #1375 for more details

  12. added a commit that references this issue on Sep 9, 2019
    4f90437
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions