- 
                Notifications
    
You must be signed in to change notification settings  - Fork 8.5k
 
Refactor cleanPath switch cases #1968
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
830f3c6    to
    ec700b0      
    Compare
  
    
          Codecov Report
 @@            Coverage Diff             @@
##           master    #1968      +/-   ##
==========================================
+ Coverage   98.83%   98.83%   +<.01%     
==========================================
  Files          40       40              
  Lines        2226     2234       +8     
==========================================
+ Hits         2200     2208       +8     
  Misses         14       14              
  Partials       12       12
 Continue to review full report at Codecov. 
  | 
    
ec700b0    to
    b073cd8      
    Compare
  
    | 
           @styd Could you provide the benchmark before and after? Thanks.  | 
    
116192e    to
    4f721a4      
    Compare
  
    | 
           I added benchmark but the result is not as I expected it would be. Do you happen to know why? Did I do the benchmark wrong?  | 
    
| 
           After I added some test data (for when a two dots sequence is not removed), the refactored cleanPath always runs slightly faster in my computer: $ go test -bench BenchmarkCleanPath -benchtime=5s
[GIN] 2019/09/06 - 22:05:53 | 200 |       3.323µs |       192.0.2.1 | GET      /name1/api
[GIN] 2019/09/06 - 22:05:53 | 200 |       1.199µs |       192.0.2.1 | GET      /name2/api
[GIN] 2019/09/06 - 22:05:53 | 200 |       4.283µs |       192.0.2.1 | GET      /test/copy/race
goos: linux
goarch: amd64
pkg: github.com/gin-gonic/gin
BenchmarkCleanPath/OldCleanPath-8                2164497              2762 ns/op
BenchmarkCleanPath/NewCleanPath-8                2218494              2746 ns/op
PASS
ok      github.com/gin-gonic/gin        17.854s | 
    
| 
           Please fix conflicts and move to 1.11  | 
    
| 
           Please fix the conflicts.  | 
    
Hi, I'm thinking of removing some checking repetitions.
Although it's slightly less readable, it should perform faster as there are less comparisons for some cases.
For example, you don't have to repeatedly check if
p[r]is'.'when the next byte is not the last.