weixin_39626181
weixin_39626181
2021-01-08 14:35

Refactor the extension method IsNullOrWhiteSpace() to use the native version

Prerequisites

  • [X] I have written a descriptive pull-request title
  • [X] I have linked this PR to an issue on the tracker at http://issues.umbraco.org/issue/U4-8199

Description

The IsNullOrWhiteSpace() extension method's implementation can be replaced by a call to the native, static version with no loss in execution speed (there's actually a small gain on average). The main two reasons for the replacement, however, are a simple reduction in Core logic and no new string construction just to count the length. The call to Trim() could return a new string which is then thrown away. The native version steps along the string and is therefore pure, as this version now is.

(I also fixed the comment on the property VersionCheckPeriod.)

该提问来源于开源项目:umbraco/Umbraco-CMS

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

9条回答

  • weixin_39626181 weixin_39626181 4月前

    Thanks! Would you be happy if I start replacing the extension method calls with native calls? I imagined this to be an intermediate step if it was approved.

    点赞 评论 复制链接分享
  • weixin_39531834 weixin_39531834 4月前

    Yeah, I think that's fine as long as you're super careful to check the before/after results are the same. If returned data suddenly starts changing it might start breaking things for people.

    点赞 评论 复制链接分享
  • weixin_39626181 weixin_39626181 4月前

    Of course. I'll be careful :-) I always check everything before and after; I added ten unit tests for this PR just to modify one line of code :-) Perhaps I should raise a new ticket to ensure all the work is tracked bit by bit. I'll probably summit small PRs as I do each change rather than a single PR that changes lots of code.

    点赞 评论 复制链接分享
  • weixin_39531834 weixin_39531834 4月前

    Yes please, small PRs and an issue for each PR would be super awesome!

    点赞 评论 复制链接分享
  • weixin_39765325 weixin_39765325 4月前

    I prefer the extension method syntax so please don't change it to string.IsNullOrWhitespace everywhere. It's good you changed the underlying logic though (it might have been manually done because a long time ago the net framework may not have had the native method).

    点赞 评论 复制链接分享
  • weixin_39531834 weixin_39531834 4月前

    Ah, to clarify, I think meant changing the underlying code of other methods here with their native methods (exactly the same as what was just done to turn the manual null/empty check into the native .net one).

    点赞 评论 复制链接分享
  • weixin_39765325 weixin_39765325 4月前

    Yup if there's other custom logic underlying our extension methods that can can be replaced with native methods that we weren't aware of then for sure.

    点赞 评论 复制链接分享
  • weixin_39626181 weixin_39626181 4月前

    Yup, exactly :-)

    No problem, thanks for giving me the opportunity to help :-)

    点赞 评论 复制链接分享
  • weixin_39531834 weixin_39531834 4月前

    Wonderful! I am not sure why we have this as an extension method but.. oh well ;-)

    点赞 评论 复制链接分享

相关推荐