You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-issues@jackrabbit.apache.org by "Julian Reschke (Jira)" <ji...@apache.org> on 2023/03/22 10:15:00 UTC

[jira] [Comment Edited] (OAK-9819) Improve Node.hasProperty/getProperty and Node.hasNode/getNode combinations

    [ https://issues.apache.org/jira/browse/OAK-9819?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17702821#comment-17702821 ] 

Julian Reschke edited comment on OAK-9819 at 3/22/23 10:14 AM:
---------------------------------------------------------------

trunk: (1.44.0) [e40907df72|https://github.com/apache/jackrabbit-oak/commit/e40907df72edb9b560d1caf5aab026f54d706dca] [1f34f6ee48|https://github.com/apache/jackrabbit-oak/commit/1f34f6ee48005ef1d5f0ed2d4c03d7b6fbeea6c9]
1.22: [246df10b62|https://github.com/apache/jackrabbit-oak/commit/246df10b62aa5b230b319a1f382778392c90167f] [99505fc140|https://github.com/apache/jackrabbit-oak/commit/99505fc14022bdc3ada5292a7c97a879f85e6a60]



was (Author: reschke):
trunk: (1.44.0) [e40907df72|https://github.com/apache/jackrabbit-oak/commit/e40907df72edb9b560d1caf5aab026f54d706dca] [1f34f6ee48|https://github.com/apache/jackrabbit-oak/commit/1f34f6ee48005ef1d5f0ed2d4c03d7b6fbeea6c9]

> Improve Node.hasProperty/getProperty and Node.hasNode/getNode combinations
> --------------------------------------------------------------------------
>
>                 Key: OAK-9819
>                 URL: https://issues.apache.org/jira/browse/OAK-9819
>             Project: Jackrabbit Oak
>          Issue Type: Improvement
>          Components: jackrabbit-api, jcr
>    Affects Versions: 1.42.0
>            Reporter: Joerg Hoh
>            Assignee: Angela Schreiber
>            Priority: Major
>             Fix For: 1.44.0, 1.22.15
>
>         Attachments: OAK-9819.patch
>
>
> In many applications using JCR I see this pattern:
> {noformat:title=application code v1}
> if (jcrNode.hasProperty(PROP) {
>   value = jcrNode.getProperty(PROP);
> }
> {noformat}
> I checked the implementation behind and found that Oak's NodeImpl implements {{hasProperty}} almost identical to the {{getProperty}} with 
> {noformat}
> node.getPropertyOrNull(oakPath) != null;
> {noformat}
> That means that the above mentioned JCR code snippet invokes {{node.getPropertyOrNull}} twice. This could be improved by exposing a new method {{getPropertyOrNull}}, in which the above code could be written like this:
> {noformat:title=application code v2}
> tmpProp = jcrNode.getPropertyOrNull(PROP);
> if (tmpProp != null) {
>   value = tmpProp;
> }
> {noformat}
> In this case there just the {{jcrNode.getPropertyOrNull}} method would do a single call into call, saving us the overhead of a second if the property is there.
> Of course this cannot go into the JCR Node interface, but we could extend the {{JackrabbitNode}} with this.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)