Skip to content

Commit

Permalink
Remember deaccented versions.
Browse files Browse the repository at this point in the history
Speeds up a long conflictassign render by a bit less than 10%.
  • Loading branch information
kohler committed Aug 7, 2023
1 parent dafefb6 commit fd23280
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
20 changes: 17 additions & 3 deletions src/author.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Author {
public $affiliation = "";
/** @var ?string */
private $_name;
/** @var ?array{string,string,string} */
/** @var null|Author|array{string,string,string} */
private $_deaccents;
/** @var ?int */
public $contactId;
Expand All @@ -37,8 +37,9 @@ class Author {
const COLLABORATORS_INDEX = -200;
const UNINITIALIZED_INDEX = -400; // see also PaperConflictInfo

/** @param null|string|object $x */
function __construct($x = null) {
/** @param null|string|object $x
* @param null|1|2|3|4|5 $status */
function __construct($x = null, $status = null) {
if (is_object($x)) {
$this->firstName = $x->firstName;
$this->lastName = $x->lastName;
Expand All @@ -47,6 +48,7 @@ function __construct($x = null) {
} else if ($x !== null && $x !== "") {
$this->assign_string($x);
}
$this->status = $status;
}

/** @param string $s
Expand Down Expand Up @@ -105,6 +107,15 @@ static function make_user($u) {
return $au;
}

/** @return self */
function copy() {
$au = clone $this;
if (!is_object($this->_deaccents)) {
$au->_deaccents = $this;
}
return $au;
}

/** @param Author|Contact $o */
function merge($o) {
if ($this->email === "") {
Expand Down Expand Up @@ -252,6 +263,9 @@ function name_h($flags = 0) {
/** @param 0|1|2 $component
* @return string */
function deaccent($component) {
if (is_object($this->_deaccents)) {
return $this->_deaccents->deaccent($component);
}
if ($this->_deaccents === null) {
$this->_deaccents = [
strtolower(UnicodeHelper::deaccent($this->firstName)),
Expand Down
1 change: 1 addition & 0 deletions src/authormatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class AuthorMatcher extends Author {
private $firstName_matcher;
/** @var ?TextPregexes */
private $lastName_matcher;
/** @var ?array{list<string>,string|false,string} */
private $affiliation_matcher;
/** @var ?TextPregexes|false */
private $general_pregexes_ = false;
Expand Down
2 changes: 1 addition & 1 deletion src/contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -5146,7 +5146,7 @@ function can_edit_tag_anno($tag) {
/** @return non-empty-list<AuthorMatcher> */
function aucollab_matchers() {
if ($this->_aucollab_matchers === null) {
$this->_aucollab_matchers = [new AuthorMatcher($this)];
$this->_aucollab_matchers = [new AuthorMatcher($this, Author::STATUS_AUTHOR)];
foreach ($this->collaborator_generator() as $m) {
$this->_aucollab_matchers[] = $m;
}
Expand Down
29 changes: 7 additions & 22 deletions src/paperinfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,6 @@ class PaperInfoSet implements IteratorAggregate, Countable {
public $loaded_allprefs = 0;
/** @var bool */
public $prefetched_conflict_users = false;
/** @var array<int,list<AuthorMatcher>> */
private $collaborator_matchers_by_uid = [];

/** @param PaperInfo $row
* @return PaperInfoSet */
Expand Down Expand Up @@ -384,20 +382,6 @@ function prefetch_conflict_users() {
}
}
}

/** @param Contact $u
* @return list<AuthorMatcher> */
function collaborator_matchers($u) {
$ms = $this->collaborator_matchers_by_uid[$u->contactId] ?? null;
if ($ms === null) {
$ms = [];
foreach ($u->collaborator_generator() as $m) {
$ms[] = $m;
}
$this->collaborator_matchers_by_uid[$u->contactId] = $ms;
}
return $ms;
}
}

class PaperInfo {
Expand Down Expand Up @@ -1300,12 +1284,13 @@ function collaborator_list() {
if ($cu->conflictType < CONFLICT_AUTHOR) {
continue;
}
foreach ($this->_row_set->collaborator_matchers($cu->user) as $m) {
$m = clone $m;
$m->contactId = $cu->contactId;
$m->status = Author::STATUS_NONAUTHOR;
$m->author_index = $cu->author_index;
yield $m;
foreach ($cu->user->aucollab_matchers() as $m) {
if ($m->is_nonauthor()) {
$m = $m->copy();
$m->contactId = $cu->contactId;
$m->author_index = $cu->author_index;
yield $m;
}
}
}
}
Expand Down

0 comments on commit fd23280

Please sign in to comment.