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

optimize mapper builder #3252

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mawen12
Copy link
Contributor

@mawen12 mawen12 commented Sep 26, 2024

Hi, I have found the XMLMapperBuilder contains two points can be optimized.

First: use method instead of parent variable

private void cacheElement(XNode context) {
  ...
  Class<? extends Cache> typeClass = typeAliasRegistry.resolveAlias(type);
  ...
  Class<? extends Cache> evictionClass = typeAliasRegistry.resolveAlias(eviction);
  ...
}

Its superclass is BaseBuilder which provide method resolveAlias(alias) to do this, may be can use method directly.

Second: use lambda to lazy compute

private Discriminator processDiscriminatorElement(XNode context, Class<?> resultType, List<ResultMapping> resultMappings) {
  ...
  String resultMap = caseChild.getStringAttribute("resultMap", processNestedResultMappings(caseChild, resultMappings, resultType));
  ...
}

The method getStringAttribute(value, default) return default only when value is null.
So when value is not null, default will be ignored,
By use lambda, default will be computed only when value is null.

@coveralls
Copy link

coveralls commented Sep 26, 2024

Coverage Status

coverage: 87.068%. remained the same
when pulling 9bfbfe4 on mawen12:optimize-mapper-builder
into 2967694 on mybatis:master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants