1
0
mirror of https://github.com/golang/go synced 2024-11-22 15:54:52 -07:00
The Go programming language
Go to file
Bryan Boreham c5430dc1d8 regexp: allow patterns with no alternates to be one-pass
Check whether a regex has any 'alt' instructions before rejecting it as one-pass.
Previously `^abc` would run the backtrack matcher.

I tried to make the comment match what the code does now.

Updates #21463

```
name                            old time/op    new time/op    delta
Find-8                             167ns ± 1%     170ns ± 3%     ~     (p=0.500 n=5+5)
FindAllNoMatches-8                88.8ns ± 5%    87.3ns ± 0%     ~     (p=0.095 n=5+5)
FindString-8                       166ns ± 3%     164ns ± 0%     ~     (p=0.063 n=5+5)
FindSubmatch-8                     191ns ± 1%     191ns ± 0%     ~     (p=0.556 n=4+5)
FindStringSubmatch-8               183ns ± 0%     182ns ± 0%   -0.43%  (p=0.048 n=5+5)
Literal-8                         50.3ns ± 0%    50.1ns ± 0%   -0.40%  (p=0.016 n=5+4)
NotLiteral-8                       914ns ± 0%     927ns ± 7%     ~     (p=0.730 n=5+5)
MatchClass-8                      1.20µs ± 1%    1.22µs ± 6%     ~     (p=0.738 n=5+5)
MatchClass_InRange-8              1.20µs ± 6%    1.21µs ± 6%     ~     (p=0.548 n=5+5)
ReplaceAll-8                       796ns ± 0%     792ns ± 0%   -0.51%  (p=0.032 n=5+5)
AnchoredLiteralShortNonMatch-8    41.0ns ± 2%    34.2ns ± 2%  -16.47%  (p=0.008 n=5+5)
AnchoredLiteralLongNonMatch-8     53.3ns ± 0%    34.3ns ± 3%  -35.74%  (p=0.008 n=5+5)
AnchoredShortMatch-8              74.0ns ± 2%    75.8ns ± 0%   +2.46%  (p=0.032 n=5+4)
AnchoredLongMatch-8                146ns ± 3%      76ns ± 1%  -48.12%  (p=0.008 n=5+5)
OnePassShortA-8                    424ns ± 0%     423ns ± 0%     ~     (p=0.222 n=5+4)
NotOnePassShortA-8                 373ns ± 1%     375ns ± 2%     ~     (p=0.690 n=5+5)
OnePassShortB-8                    315ns ± 2%     308ns ± 0%   -2.12%  (p=0.008 n=5+5)
NotOnePassShortB-8                 244ns ± 3%     239ns ± 0%     ~     (p=0.476 n=5+5)
OnePassLongPrefix-8               61.6ns ± 2%    60.9ns ± 0%   -1.13%  (p=0.016 n=5+4)
OnePassLongNotPrefix-8             236ns ± 3%     230ns ± 0%     ~     (p=0.143 n=5+5)
```

Change-Id: I8a94b53bc761cd7ec89923c905ec8baaaa58a5fd
GitHub-Last-Rev: e9e0c29b74
GitHub-Pull-Request: golang/go#48748
Reviewed-on: https://go-review.googlesource.com/c/go/+/353711
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Russ Cox <rsc@golang.org>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Commit-Queue: Ian Lance Taylor <iant@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2024-07-24 01:01:48 +00:00
.github .github/ISSUE_TEMPLATE/03-gopls.yml: use textarea for gopls version 2024-05-24 17:09:04 +00:00
api crypto/tls: apply QUIC session event flag to QUICResumeSession events 2024-06-25 17:08:08 +00:00
doc cmd/cgo: error on multiple incompatible function declarations 2024-07-23 21:11:11 +00:00
lib/time lib/time: use consistent directory in mkzip usage message 2024-03-04 17:32:07 +00:00
misc misc/ios: rework exec wrapper to only support simulator 2024-06-18 16:32:49 +00:00
src regexp: allow patterns with no alternates to be one-pass 2024-07-24 01:01:48 +00:00
test test: add test cases for local not-in-heap types 2024-07-24 00:11:49 +00:00
.gitattributes
.gitignore runtime,internal: move runtime/internal/sys to internal/runtime/sys 2024-07-23 19:05:35 +00:00
codereview.cfg
CONTRIBUTING.md
go.env
LICENSE
PATENTS
README.md README: fix CC BY license name 2024-07-22 17:45:27 +00:00
SECURITY.md SECURITY.md: update the Reporting a Vulnerability link 2023-09-22 21:17:24 +00:00

The Go Programming Language

Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.

Gopher image Gopher image by Renee French, licensed under Creative Commons 4.0 Attribution license.

Our canonical Git repository is located at https://go.googlesource.com/go. There is a mirror of the repository at https://github.com/golang/go.

Unless otherwise noted, the Go source files are distributed under the BSD-style license found in the LICENSE file.

Download and Install

Binary Distributions

Official binary distributions are available at https://go.dev/dl/.

After downloading a binary release, visit https://go.dev/doc/install for installation instructions.

Install From Source

If a binary distribution is not available for your combination of operating system and architecture, visit https://go.dev/doc/install/source for source installation instructions.

Contributing

Go is the work of thousands of contributors. We appreciate your help!

To contribute, please read the contribution guidelines at https://go.dev/doc/contribute.

Note that the Go project uses the issue tracker for bug reports and proposals only. See https://go.dev/wiki/Questions for a list of places to ask questions about the Go language.