Commit Graph

57 Commits

Author SHA1 Message Date
Tom Thorogood 41a7730f43
Remove space between NextLabel func and doc comment (#1410)
This was mistakenly added in #1406.
2023-01-06 08:51:52 +01:00
Miek Gieben 3b7e0b9bdd
NextLabel: document neg. offset will panic (#1406)
Fixes: #1404

Signed-off-by: Miek Gieben <miek@miek.nl>

Signed-off-by: Miek Gieben <miek@miek.nl>
2023-01-05 07:52:29 +01:00
Shubhendra Singh Chauhan 2f14d104f3
improve code quality (#1228)
* Combine multiple `append`s into a single call

* Fix Yoda conditions

* Fix check for empty string

* revert "combine multiple `append`s"
2021-02-25 17:01:55 +01:00
Miek Gieben 9dcf47a409
Doc updates (#1075)
* Doc updates

Was reading https://pkg.go.dev/github.com/miekg/dns?tab=doc and spotted
some types and things to could be slightly better.

Make v unexported, as this version stuff should not be part of the
public API.

Signed-off-by: Miek Gieben <miek@miek.nl>

* fix test

Signed-off-by: Miek Gieben <miek@miek.nl>
2020-02-14 22:47:21 +01:00
Julian Picht 22cda6dc4f Speed up NextLabel and PrevLabel (#1039)
* change NextLabel and PrevLabel to be faster

This reduces readability, but they are in the hot path of coredns.

* @redyeti pointed out, that my implementation disregarded triple backslashes

* add synthetic benchmark-tests for PrevLabel and NextLabel

* rename ii -> j

* invert compare

* PrevLabel: add empty string check + test case

* NextLabel: fix and add testcase for NextLabel("", offset>0)
2019-12-04 07:25:08 +00:00
Miek Gieben 1cd342c79a
Revert "labels: eliminate most allocations and improve perf by 15-65% (#1007)" (#1022)
This reverts commit ab6ac402ba.

This break CoreDNS tests and probably a lot of other apps as well.
Reverted
2019-10-04 10:26:59 +01:00
Charlie Vieth ab6ac402ba labels: eliminate most allocations and improve perf by 15-65% (#1007)
* labels: eliminate most allocations and improve perf by 15-65%

This commit changes the labels functions to step through labels
section-by-section instead of splitting them and thus allocating
a slice.

Where possible allocations are reduced to 0.

```
benchmark                         old ns/op     new ns/op     delta
BenchmarkSplitLabels-12           41.4          34.9          -15.70%
BenchmarkLenLabels-12             25.8          15.5          -39.92%
BenchmarkCompareDomainName-12     107           39.3          -63.27%
BenchmarkIsSubDomain-12           348           120           -65.52%

benchmark                         old allocs     new allocs     delta
BenchmarkSplitLabels-12           1              1              +0.00%
BenchmarkLenLabels-12             0              0              +0.00%
BenchmarkCompareDomainName-12     2              0              -100.00%
BenchmarkIsSubDomain-12           6              0              -100.00%

benchmark                         old bytes     new bytes     delta
BenchmarkSplitLabels-12           32            32            +0.00%
BenchmarkLenLabels-12             0             0             +0.00%
BenchmarkCompareDomainName-12     64            0             -100.00%
BenchmarkIsSubDomain-12           192           0             -100.00%
```

* labels: fix CompareDomainName and improve tests
2019-09-21 08:46:30 +01:00
Tom Thorogood d8ff986484 Use for range loops instead of manual for loops (#937)
* Use for range loops instead of manual loops

* Use for range loop in Msg.CopyTo

This is a separate commit as the change is slightly more than just
switching the loop style.

* Use for range loop in DNSKEY.publicKeyRSA

* Add explen comment to DNSKEY.publicKeyRSA
2019-03-18 07:06:44 +00:00
Tom Thorogood 513c1ff221 Simplify and unify various returns (#893) 2019-01-04 10:19:42 +00:00
Tom Thorogood 09499bd07f Use IsFqdn and Fqdn helper functions more (#892) 2019-01-04 08:13:00 +00:00
Tom Thorogood c9b812d1d9 Remove redundant parenthesis (#727)
* Remove redundant parenthesis

These were caught with:
    gofmt -r '(a) -> a' -w *.go

This commit only includes the changes where the formatting makes the
ordering of operations clear.

* Remove more redundant parenthesis

These were caught with:
    gofmt -r '(a) -> a' -w *.go

This commit includes the remaining changes where the formatting does not
make the ordering of operations as clear as the previous commit.
2018-08-16 17:05:27 +01:00
Miek Gieben 54ceb83127 Optimize CompareDomainName (#535)
Optimize CompareDomainName:
old: BenchmarkCompareDomainName-2   	 1000000	      1869 ns/op	      64 B/op	       2 allocs/op
new: BenchmarkCompareDomainName-2   	 2000000	       854 ns/op	      64 B/op	       2 allocs/op

This removes the strings.ToLower and fixes the documentation. It also
does not Fqdn's the names anymore (the documentation said we didn't, now
the documentation is right again).
Unlike what the documentation said we are comparing in a ignore-case
manor, add helper function equal that does this without calling
strings.ToLower.
2017-10-15 16:22:03 +02:00
Roland Bracewell Shoemaker 6ebcb714d3 NSEC/3 Cover+Match cleanup (#479)
* Initial NSEC cleanup

* Use readable names

* Finish tests

* Use existing functions, simplify hash/zone split

* Make IsSubDomain case insensitive, add tests

* Use internal Split instead of strings.Split
2017-04-12 19:47:48 +01:00
Erik Dubbelboer 48ab6605c6 go fmt (#355) 2016-05-12 07:43:16 +01:00
Miek Gieben 84e9295e47 Improve docs on the label functions
Explicitly mention that the domain s must be valid before
given it to these functions.

Fixes: 306
2016-02-28 08:37:17 +00:00
tal@whatexit.org 808f9308ef Added new functions: TrimDomainName()/AddOrigin()
* TrimDomainName() Trims the domain off a FQDN.
  * AddOrigin() Adds a domain to a shortname or leaves a FQDN alone.
2016-01-25 12:08:29 -05:00
Miek Gieben 5b9c36bf67 Small doc cleanups 2015-08-23 12:55:01 +01:00
Miek Gieben 114b68f41b go vet fixes 2015-08-23 07:24:08 +01:00
Miek Gieben e6b3ae712b extra docs 2014-09-21 07:43:46 +01:00
Miek Gieben 0aa3021a83 Remove all copyright notices
Use the central COPYRIGHT file.
2014-09-11 20:57:37 +01:00
Alex Ciuba e429f38a76 Overallocate label index buffer 2014-01-25 14:21:46 -05:00
Miek Gieben e78a7436aa Check if the string is empty. 2014-01-18 22:02:49 +00:00
Miek Gieben f938bc70df Remove long deprecated functions too 2013-09-30 20:24:18 +01:00
Miek Gieben 1f586fdcda Fixup PrevLabel and add a test 2013-09-12 09:58:42 +01:00
Miek Gieben 4ba292d8b6 Add a PrevLabel function to count back from the right 2013-09-12 09:36:39 +01:00
Miek Gieben c67fc3a2a1 Add more tests for the labels 2013-09-12 09:18:54 +01:00
Miek Gieben 9764818db3 Make CountLabel faster
We don't need an allocation here, it works ok for non-fqdns and fqdns
2013-09-12 09:11:19 +01:00
Miek Gieben b663a82eb3 Move deprecated function to the bottom of the file 2013-09-12 09:07:27 +01:00
Miek Gieben 8eb72eea8a Add . 2013-09-12 09:03:09 +01:00
Miek Gieben 08e7365dc2 Make SplitLabels faster
don't allocate a new string at all, it does not matter is the given
string is not fully qualified.
2013-09-12 08:57:37 +01:00
Miek Gieben 7ef3106262 Add panics to make older Go versions happy 2013-07-12 14:27:16 +00:00
Miek Gieben 55aa4480c7 Fix some typos 2013-06-27 19:46:26 +01:00
Ray Bejjani 9d2d8b36eb SplitDomainName handles non-FQDN labels correctly, doesn't return '.' in parts.
SplitDomainName would always include the '.' after each label segment. This was
inconsistent with the "." case (were it returned nil) and didn't seem too useful
since it required more processing to remove the '.' (like when building a
compression dictionary in Msg.Len() or Msg.Pack()). It also had issues with the
last segment, not including it in the split. It now returns all segments,
including the last, irrespective of the label being fully qualified.
A test has also been added to ensure no regressions.
2013-06-25 10:53:30 -07:00
Miek Gieben 45640bc8bd Slightly better documentation 2013-06-24 08:14:30 +00:00
Miek Gieben 38ea608d79 Rename the Label* functions
SplitLabels -> SplitDomainName
CompareLabels -> CompareDomainName
LenLabels -> CountLabel
          -> NextLabel was added as a simple iterator-like function
2013-06-22 07:21:15 +00:00
Miek Gieben 74a0da119d Uh uppercase it here too 2013-06-21 15:31:19 +00:00
Miek Gieben ef73958b14 Make nextLabel public 2013-06-21 15:23:31 +00:00
Miek Gieben 9640d43c82 Make SplitLabels use Split 2013-06-21 15:17:12 +00:00
Miek Gieben 939abbfea7 Re-arrange some comments 2013-06-21 08:53:24 +00:00
Miek Gieben a16b289765 Add todo 2013-06-20 20:36:13 +00:00
Miek Gieben 1d22bfdb4d Add more efficient label test functions
Also add tests for it.
2013-06-20 14:24:14 +00:00
Miek Gieben cb1a259368 Add the first of faster/mem eff. labsl functions 2013-06-20 07:49:18 +01:00
Miek Gieben 81941d4422 Update all copyright notices 2013-05-12 16:15:52 +02:00
Miek Gieben a2d98be202 lowercase the names 2012-09-04 20:08:55 +02:00
Miek Gieben af2f485c8e Fix IsSubDomain 2012-07-16 19:16:36 +02:00
Miek Gieben 393719d659 Add LenLabels function - no allocations 2012-07-16 08:51:39 +02:00
Miek Gieben 89c05b4f74 gofmt 2012-02-23 19:37:08 +01:00
Miek Gieben 95ffaca79d typo 2012-02-14 22:43:04 +01:00
Miek Gieben 827e4a476f Force the root label to have 0 labels 2012-02-14 22:26:18 +01:00
Miek Gieben 2cb265697e Documentation
Need to think about the non-existing root-label and the label
functions.
2012-02-12 11:34:28 +01:00