Opened 4 months ago

Last modified 2 months ago

#7016 new change

Convert serialization functions into generators

Reported by: mjethani Assignee: jsonesen
Priority: P3 Milestone:
Module: Core Keywords:
Cc: jsonesen, sebastian, erikvold Blocked By:
Blocking: Platform: Unknown / Cross platform
Ready: yes Confidential: no
Tester: Unknown Verified working: no
Review URL(s):

Description

Background

The serialization functions in the Filter and Subscripton classes look somewhat like this (pseudocode):

/**
 * @param {string[]} buffer
 */
function serialize(buffer)
{
  buffer.push("[Filter]");
  buffer.push("text=" + this.text);
}

The exportData function in lib/filterStorage.js has code like this:

let buffer = [];
for (let filter of filters)
{
  filter.serialize(buffer);
  for (let line of buffer)
    yield line;
  buffer.splice(0);
}

exportData is a generator function. It is wasteful to create a temporary array, pass it to the serialization function for each filter, and empty it out for the next filter in the list. Instead, the serialization function could also be a generator that yields each "line" to be serialized.

With this change, the code in exportData would look like this instead:

for (let filter of filters)
  yield* filter.serialize();

What to change

Convert the serialization functions in the Filter and Subscription classes to generators, and make the corresponding changes in the exportData function.

Change History (4)

comment:1 Changed 4 months ago by jsonesen

  • Owner set to jsonesen

comment:2 Changed 4 months ago by sebastian

  • Cc sebastian added

Please add some integration notes to adapt this code in
adblockpluschrome which currently relies on subscription's serialize() and serializeFilters() methods to take an array as an argument.

comment:3 Changed 3 months ago by abpbot

A commit referencing this issue has landed:
Issue 7016 - Convert serialization functions into generators

comment:4 Changed 2 months ago by erikvold

  • Cc erikvold added
Note: See TracTickets for help on using tickets.