Skip to content

Commit

Permalink
Remove unneeded calls to substring()
Browse files Browse the repository at this point in the history
  • Loading branch information
vigdorchik committed Oct 15, 2012
1 parent 5691373 commit aa27396
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/compiler/scala/tools/nsc/util/DocStrings.scala
Expand Up @@ -100,10 +100,10 @@ object DocStrings {
* can override the parent symbol's sections
*/
def mergeUsecaseSections(str: String, idxs: List[Int]): List[Int] = {
idxs.indexWhere(str.substring(_).startsWith("@usecase")) match {
idxs.indexWhere(str.startsWith("@usecase", _)) match {
case firstUCIndex if firstUCIndex != -1 =>
val commentSections = idxs.take(firstUCIndex)
val usecaseSections = idxs.drop(firstUCIndex).filter(str.substring(_).startsWith("@usecase"))
val usecaseSections = idxs.drop(firstUCIndex).filter(str.startsWith("@usecase", _))
commentSections ::: usecaseSections
case _ =>
idxs
Expand All @@ -114,7 +114,7 @@ object DocStrings {
* Merge the inheritdoc sections, as they never make sense on their own
*/
def mergeInheritdocSections(str: String, idxs: List[Int]): List[Int] =
idxs.filterNot(str.substring(_).startsWith("@inheritdoc"))
idxs.filterNot(str.startsWith("@inheritdoc", _))

/** Does interval `iv` start with given `tag`?
*/
Expand Down Expand Up @@ -190,24 +190,26 @@ object DocStrings {

/** Extract the section parameter */
def extractSectionParam(str: String, section: (Int, Int)): String = {
assert(str.substring(section._1).startsWith("@param") ||
str.substring(section._1).startsWith("@tparam") ||
str.substring(section._1).startsWith("@throws"))
val (beg, _) = section
assert(str.startsWith("@param", beg) ||
str.startsWith("@tparam", beg) ||
str.startsWith("@throws", beg))

val start = skipWhitespace(str, skipTag(str, section._1))
val start = skipWhitespace(str, skipTag(str, beg))
val finish = skipIdent(str, start)

str.substring(start, finish)
}

/** Extract the section text, except for the tag and comment newlines */
def extractSectionText(str: String, section: (Int, Int)): (Int, Int) = {
if (str.substring(section._1).startsWith("@param") ||
str.substring(section._1).startsWith("@tparam") ||
str.substring(section._1).startsWith("@throws"))
(skipWhitespace(str, skipIdent(str, skipWhitespace(str, skipTag(str, section._1)))), section._2)
val (beg, end) = section
if (str.startsWith("@param", beg) ||
str.startsWith("@tparam", beg) ||
str.startsWith("@throws", beg))
(skipWhitespace(str, skipIdent(str, skipWhitespace(str, skipTag(str, beg)))), end)
else
(skipWhitespace(str, skipTag(str, section._1)), section._2)
(skipWhitespace(str, skipTag(str, beg)), end)
}

/** Cleanup section text */
Expand Down

0 comments on commit aa27396

Please sign in to comment.