Make WordPress Core

Opened 3 years ago

Closed 3 years ago

#57527 closed enhancement (fixed)

Duotone: PHP code quality improvements

Reported by: mamaduka's profile Mamaduka Owned by: hellofromtonya's profile hellofromTonya
Milestone: 6.2 Priority: normal
Severity: normal Version:
Component: Editor Keywords: has-patch gutenberg-merge commit
Focuses: performance Cc:

Description (last modified by hellofromTonya)

PHP code quality improvements:

  • Use in/decrementors where appropriate.

Why? They're more performant than an assignment with a calculation.
See https://github.com/WordPress/gutenberg/pull/44551.

  • Don't check if constants set by wp_initial_constants() are defined.

This reduces the number of defined() calls for constants which are always set. Why? wp_initial_constants() makes sure that all the default constants are set.
See https://github.com/WordPress/gutenberg/pull/45979.

Change History (9)

#2 @Mamaduka
3 years ago

  • Milestone changed from Awaiting Review to 6.2

@Mamaduka commented on PR #3890:


3 years ago
#3

cc @hellofromtonya

#4 @hellofromTonya
3 years ago

  • Description modified (diff)
  • Focuses performance added
  • Keywords gutenberg-merge added
  • Owner set to hellofromTonya
  • Status changed from new to reviewing
  • Summary changed from Duotone: Two minor code quality fixes to Duotone: PHP code quality improvements

#5 @hellofromTonya
3 years ago

  • Keywords commit added

Self-assigning for commit. Planning to do 2 separate atomic commits to capture the context of why each improvement is being made.

#6 @hellofromTonya
3 years ago

In 55140:

Editor: Use in/decrementors in wp_tinycolor_hue_to_rgb().

Replaces += and -= with ++$t and --$t (in/decrementors) within the wp_tinycolor_hue_to_rgb().

Why? For performance: in/decrementors are more performant than an assignment with a calculation.

References:

Follow-up to [50929].

Props jrf, czapla, antonvlasenko, aristath, mamaduka.
See #57527.

#7 @hellofromTonya
3 years ago

In 55141:

Editor: Remove WP_DEBUG defined check in wp_tinycolor_hue_to_rgb().

The constant WP_DEBUG is a default constant that is set within wp_initial_constants() when not defined. This means the constant will always be defined, thus making the defined( 'WP_DEBUG' ) unnecessary.

Removing the defined() provides these benefits:

  • Makes the code more readable.
  • Tiny performance optimization.

References:

Follow-up to [52049].

Props ocean90, spacedmonkey, mamaduka.
See #57527.

#9 @hellofromTonya
3 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

All work is now committed. Closing the ticket.

Note: See TracTickets for help on using tickets.