The function field_info_field_map(), introduced in Drupal 7.22, is more memory-efficient than field_info_fields(). That is, provided the latter isn't called at all during the request.

See https://drupal.org/node/1915646 for more information.

A small patch is attached, which removes the only instance where Rules didn't conform.

Comments

dave reid’s picture

  1. +++ b/modules/entity.rules.inc
    @@ -456,7 +456,10 @@ function rules_condition_entity_is_new_help() {
    +  $fields_func = version_compare(VERSION, '7.22', '>=') ? 'field_info_field_map' : 'field_info_fields';
    

    Why not just $fields = ... ? field_info_field_map() and field_info_fields();

    Possibly just do a function_exists() instead of version_compare().

  2. +++ b/modules/entity.rules.inc
    @@ -456,7 +456,10 @@ function rules_condition_entity_is_new_help() {
    +  foreach (array_keys($fields_func()) as $field_name) {
    

    We could even remove the foreach() here and just do return drupal_map_assoc(array_keys($fields));

pjcdawkins’s picture

StatusFileSize
new807 bytes

Thanks for reviewing. New patch attached. The version_compare() is due to your earlier advice.

fago’s picture

Status: Needs review » Needs work

Let's use function_exists() as those calls are pretty cheap.

sanchiz’s picture

Status: Needs work » Needs review
Issue tags: +dcdn-sprint
StatusFileSize
new847 bytes

New patch with function_exists().

dasjo’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to go.

fago’s picture

Status: Reviewed & tested by the community » Fixed

Thanks, committed.

  • Commit 34d0eb9 on 7.x-2.x by fago:
    Issue #2206545 by pjcdawkins, sanchiz: Replace field_info_fields() with...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.