use IndexByte instead of IndexRune everywhere because it's faster.
This commit is contained in:
@@ -22,11 +22,11 @@ type MessageParser interface {
|
|||||||
|
|
||||||
// Deprecated: use NewMessageParser instead
|
// Deprecated: use NewMessageParser instead
|
||||||
func ParseMessage(message string) Envelope {
|
func ParseMessage(message string) Envelope {
|
||||||
firstQuote := strings.IndexRune(message, '"')
|
firstQuote := strings.IndexByte(message, '"')
|
||||||
if firstQuote == -1 {
|
if firstQuote == -1 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
secondQuote := strings.IndexRune(message[firstQuote+1:], '"')
|
secondQuote := strings.IndexByte(message[firstQuote+1:], '"')
|
||||||
if secondQuote == -1 {
|
if secondQuote == -1 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,11 +14,11 @@ func NewMessageParser() MessageParser {
|
|||||||
type messageParser struct{}
|
type messageParser struct{}
|
||||||
|
|
||||||
func (messageParser) ParseMessage(message string) (Envelope, error) {
|
func (messageParser) ParseMessage(message string) (Envelope, error) {
|
||||||
firstQuote := strings.IndexRune(message, '"')
|
firstQuote := strings.IndexByte(message, '"')
|
||||||
if firstQuote == -1 {
|
if firstQuote == -1 {
|
||||||
return nil, errors.New("malformed json")
|
return nil, errors.New("malformed json")
|
||||||
}
|
}
|
||||||
secondQuote := strings.IndexRune(message[firstQuote+1:], '"')
|
secondQuote := strings.IndexByte(message[firstQuote+1:], '"')
|
||||||
if secondQuote == -1 {
|
if secondQuote == -1 {
|
||||||
return nil, errors.New("malformed json")
|
return nil, errors.New("malformed json")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ func extractEventID(jsonStr string) ID {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// move to the next quote
|
// move to the next quote
|
||||||
offset := strings.IndexRune(jsonStr[start+4:], '"')
|
offset := strings.IndexByte(jsonStr[start+4:], '"')
|
||||||
start += 4 + offset + 1
|
start += 4 + offset + 1
|
||||||
|
|
||||||
// get 64 characters of the id
|
// get 64 characters of the id
|
||||||
@@ -208,7 +208,7 @@ func extractEventPubKey(jsonStr string) PubKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// move to the next quote
|
// move to the next quote
|
||||||
offset := strings.IndexRune(jsonStr[start+8:], '"')
|
offset := strings.IndexByte(jsonStr[start+8:], '"')
|
||||||
start += 8 + offset + 1
|
start += 8 + offset + 1
|
||||||
|
|
||||||
// get 64 characters of the pubkey
|
// get 64 characters of the pubkey
|
||||||
@@ -225,11 +225,11 @@ func extractDTag(jsonStr string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// move to the next quote
|
// move to the next quote
|
||||||
offset := strings.IndexRune(jsonStr[start+4:], '"')
|
offset := strings.IndexByte(jsonStr[start+4:], '"')
|
||||||
start += 4 + offset + 1
|
start += 4 + offset + 1
|
||||||
|
|
||||||
// find the ending quote
|
// find the ending quote
|
||||||
end := strings.IndexRune(jsonStr[start:], '"')
|
end := strings.IndexByte(jsonStr[start:], '"')
|
||||||
if end == -1 {
|
if end == -1 {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ func Parse(content string) iter.Seq[Block] {
|
|||||||
prevIndex := 0
|
prevIndex := 0
|
||||||
|
|
||||||
for index < max {
|
for index < max {
|
||||||
pu := strings.IndexRune(content[index:], ':')
|
pu := strings.IndexByte(content[index:], ':')
|
||||||
if pu == -1 {
|
if pu == -1 {
|
||||||
// reached end
|
// reached end
|
||||||
break
|
break
|
||||||
|
|||||||
Reference in New Issue
Block a user