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

CLDR-17540 update SupplementalDataInfo reader to not use reentrant XPathParts #3632

Merged
merged 3 commits into from
Apr 22, 2024

Conversation

srl295
Copy link
Member

@srl295 srl295 commented Apr 12, 2024

note this is for v46 - see also #3631

  • clarify distinction between XPathParts and SimpleXPathParts
  • push XPathParts.size() and other API up to XPathValue.size()
  • use SimpleXPathParts instead of XPathParts in SupplementalDataInfo

CLDR-17540

  • This PR completes the ticket.

ALLOW_MANY_COMMITS=true

…athParts

- clarify distinction between XPathParts and SimpleXPathParts
- push XPathParts.size() and other API up to XPathValue.size()
- use SimpleXPathParts instead of XPathParts in SupplementalDataInfo
@srl295 srl295 requested review from hagbard, macchiati and a team April 12, 2024 21:41
@srl295 srl295 self-assigned this Apr 12, 2024
@srl295
Copy link
Member Author

srl295 commented Apr 12, 2024

this was more work than made sense for v45 so split out.

*
* <p>Caches values for fast lookup.
*
* <p>For use at static init time, or anywhere a simpler API can be used, see {@link
Copy link
Member

Choose a reason for hiding this comment

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

A downside of SimpleXPathParts is that it doesn't cache, right? That should be mentioned here also, because it is a downside to using SimpleXPathParts for repeated usage.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. This should say, static init time where XPaths that are going to be read only once are used. Especially supplemental data, where all XPaths are unique and caching doesn't help.


/**
* Get the attributes for the nth element (negative index is from end). Returns null or an empty
* map if there's nothing. PROBLEM: exposes internal map
Copy link
Member

Choose a reason for hiding this comment

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

It would be better to return an ImmutableMap; that way we are guaranteed that nothing can change it.

Can discuss tradeoffs offline.

Copy link
Member

Choose a reason for hiding this comment

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

That is, something like the following.

  • from public Element makeImmutable() {
  • extract the following into a method in a common location
            if (attributes != null && !(attributes instanceof ImmutableMap)) {
                attributes = ImmutableMap.copyOf(attributes);
           }
  • From public XPathParts freeze() {
  • extract the following into a method in a common location, changing to call the above method instead of Element.makeImmutable()
            // ensure that it can't be modified. Later we can fix all the call sites to check
            // frozen.
            List<Element> temp = new ArrayList<>(elements.size());
            for (Element element : elements) {
                temp.add(element.makeImmutable());
            }
            elements = ImmutableList.copyOf(temp);
  • then change the following to call that method after the handleParse call
    SimpleXPathParts(String xpath) {
        handleParse(xpath, true);
    }

There are alternatives, eg copy the code into SimpleXPathParts, or have an Elements base class, etc.

Copy link
Member Author

Choose a reason for hiding this comment

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

PROBLEM: exposes internal map comment and code is from the original XPathParts implementation. Perhaps that's a good follow up item as a separate concern from this one?

Copy link
Member

Choose a reason for hiding this comment

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

Makes sense. Can you clone a ticket for that?

Copy link
Member Author

Choose a reason for hiding this comment

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

@srl295 srl295 requested review from macchiati and a team April 20, 2024 00:51
@srl295
Copy link
Member Author

srl295 commented Apr 20, 2024

@macchiati PTAL, updated the comments. The immutability is in another ticket

@srl295 srl295 merged commit af19649 into unicode-org:main Apr 22, 2024
10 checks passed
@srl295 srl295 deleted the srl295/cldr-17504bis branch April 22, 2024 23:40
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