Skip to content

Commit

Permalink
Replace fmt.Sscanf with strconv.Atoi for faster int conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
sabandi authored and felixge committed Sep 27, 2020
1 parent 5aa20cb commit 2bee013
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion handler.go
Expand Up @@ -3,6 +3,7 @@ package fgprof
import (
"fmt"
"net/http"
"strconv"
"time"
)

Expand All @@ -15,7 +16,7 @@ func Handler() http.Handler {
var seconds int
if s := r.URL.Query().Get("seconds"); s == "" {
seconds = 30
} else if _, err := fmt.Sscanf(s, "%d", &seconds); err != nil || seconds <= 0 {
} else if seconds, err := strconv.Atoi(s); err != nil || seconds <= 0 {
w.WriteHeader(http.StatusBadRequest)
fmt.Fprintf(w, "bad seconds: %d: %s\n", seconds, err)
}
Expand Down

0 comments on commit 2bee013

Please sign in to comment.