Skip to content

Use possessive quantifiers in routing requirements? #818

Closed
@javiereguiluz

Description

@javiereguiluz

As @stof explained in #817:

I suggest using a possessive quantifier to improve the route matching performance (Symfony generates possessive quantifiers for its builtin requirements, but custom ones need to do that themselves, as using non-possessive quantifiers can still be a valid use case)

He's technically right, but we need to decide if we do that in this Demo app or not:

// BEFORE
@Route("/{id<\d+>}/edit",methods={"GET", "POST"}, name="admin_post_edit")
@Route("/page/{page<[1-9]\d*>}", defaults={"_format"="html"}, methods={"GET"}, name="blog_index_paginated")

// AFTER
@Route("/{id<\d++>}/edit",methods={"GET", "POST"}, name="admin_post_edit")
@Route("/page/{page<[1-9]\d*+>}", defaults={"_format"="html"}, methods={"GET"}, name="blog_index_paginated")

Some pros and cons:

  • (Con) This is a Demo app not a benchmark app, so clarity is preferred over speed.
  • (Con) The \d++ and \d*+ can confuse lots of developers who don't know regexp well
  • (Pro) Using these can be a good opportunity to help teach about them.
  • (Pro) It makes the routing slightly faster
  • ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions