Skip to content

Conversation

zhangweidavid
Copy link
Contributor

@zhangweidavid zhangweidavid commented Nov 27, 2017

https://github.com/mybatis/mybatis-3/blob/master/src/main/java/org/apache/ibatis/scripting/xmltags/XMLScriptBuilder.java
These handlers are thread-safe, so they do not need to be created every time。
Using a global Map instead of local variables

#1148

@harawata
Copy link
Member

Good point. Thank you, @zhangweidavid !

@hazendaz ,
You cleaned up this class a while ago, but it would be more efficient if we reuse the HashMap instance.
I have no strong opinion about how to instantiate it, but does this PR look OK to you?

@kazuki43zoo
Copy link
Member

I think that this is good PR.

@zhangweidavid
Copy link
Contributor Author

zhangweidavid commented Nov 29, 2017

https://github.com/mybatis/mybatis-3/blob/master/src/main/java/org/apache/ibatis/reflection/factory/DefaultObjectFactory.java
I think that the method of instantiateClass in this class should be private. @harawata what do you think about this ?

map.put("otherwise", new OtherwiseHandler());
map.put("bind", new BindHandler());
return map.get(nodeName);
return nodeHandlerMap.get(nodeName);
Copy link
Member

Choose a reason for hiding this comment

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

I would remove this method and call nodeHandlerMap.get() directly.
It's redundant and the name is inaccurate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea.

@harawata
Copy link
Member

harawata commented Dec 6, 2017

I think that the method of instantiateClass in this class should be private.

Agreed!
And thank you for the additional tests. :)

@harawata harawata changed the title enhance the Mathod of nodeHandlers Avoid unnecessary object creation when parsing XML tags. Dec 13, 2017
@harawata harawata merged commit 3f0f195 into mybatis:master Dec 13, 2017
harawata added a commit that referenced this pull request Dec 13, 2017
@harawata harawata added the enhancement Improve a feature or add a new feature label Dec 13, 2017
@harawata harawata added this to the 3.4.6 milestone Dec 13, 2017
@harawata harawata self-assigned this Dec 13, 2017
@harawata
Copy link
Member

Merged. Thanks again!

pulllock pushed a commit to pulllock/mybatis-3 that referenced this pull request Oct 19, 2023
Avoid unnecessary object creation when parsing XML tags.
pulllock pushed a commit to pulllock/mybatis-3 that referenced this pull request Oct 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improve a feature or add a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants