Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(10)

Delta Between Two Patch Sets: src/pkg/strings/strings.go

Issue 12483043: code review 12483043: strings: use runtime assembly for IndexByte (Closed)
Left Patch Set: Created 10 years, 7 months ago
Right Patch Set: diff -r e285a7b170aa https://go.googlecode.com/hg/ Created 10 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « src/pkg/runtime/asm_arm.s ('k') | src/pkg/strings/strings.s » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 // Package strings implements simple functions to manipulate strings. 5 // Package strings implements simple functions to manipulate strings.
6 package strings 6 package strings
7 7
8 import ( 8 import (
9 "unicode" 9 "unicode"
10 "unicode/utf8" 10 "unicode/utf8"
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 if h == hashsep && s[:n] == sep { 148 if h == hashsep && s[:n] == sep {
149 return 0 149 return 0
150 } 150 }
151 for i := n; i < len(s); { 151 for i := n; i < len(s); {
152 h *= primeRK 152 h *= primeRK
153 h += uint32(s[i]) 153 h += uint32(s[i])
154 h -= pow * uint32(s[i-n]) 154 h -= pow * uint32(s[i-n])
155 i++ 155 i++
156 if h == hashsep && s[i-n:i] == sep { 156 if h == hashsep && s[i-n:i] == sep {
157 return i - n 157 return i - n
158 }
159 }
160 return -1
161 }
162
163 // IndexByte returns the index of the first instance of c in s, or -1 if c is no t present in s.
164 func IndexByte(s string, c byte) int {
165 for i := 0; i < len(s); i++ {
166 if s[i] == c {
167 return i
168 } 158 }
169 } 159 }
170 return -1 160 return -1
171 } 161 }
172 162
173 // LastIndex returns the index of the last instance of sep in s, or -1 if sep is not present in s. 163 // LastIndex returns the index of the last instance of sep in s, or -1 if sep is not present in s.
174 func LastIndex(s, sep string) int { 164 func LastIndex(s, sep string) int {
175 n := len(sep) 165 n := len(sep)
176 if n == 0 { 166 if n == 0 {
177 return len(s) 167 return len(s)
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 } 719 }
730 if r == tr { 720 if r == tr {
731 continue 721 continue
732 } 722 }
733 return false 723 return false
734 } 724 }
735 725
736 // One string is empty. Are both? 726 // One string is empty. Are both?
737 return s == t 727 return s == t
738 } 728 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b