Optimization
This commit is contained in:
@@ -83,8 +83,10 @@ class CodeBuilder(private val topElement: PsiElement?) {
|
|||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert(text.indexOf('\r') < 0, "No '\\r' allowed")
|
||||||
|
|
||||||
if (endOfLineCommentAtEnd) {
|
if (endOfLineCommentAtEnd) {
|
||||||
if (text[0] != '\n' && text[0] != '\r') builder.append('\n')
|
if (text[0] != '\n') builder.append('\n')
|
||||||
endOfLineCommentAtEnd = false
|
endOfLineCommentAtEnd = false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -343,14 +345,16 @@ class CodeBuilder(private val topElement: PsiElement?) {
|
|||||||
|
|
||||||
fun PsiElement.isEmptyElement() = getFirstChild() == null && getTextLength() == 0
|
fun PsiElement.isEmptyElement() = getFirstChild() == null && getTextLength() == 0
|
||||||
|
|
||||||
fun PsiWhiteSpace.lineBreakCount() = StringUtil.getLineBreakCount(getText()!!)
|
fun PsiWhiteSpace.lineBreakCount() = StringUtil.getLineBreakCount(getText())
|
||||||
|
|
||||||
fun PsiWhiteSpace.hasLineBreaks() = StringUtil.containsLineBreak(getText()!!)
|
fun PsiWhiteSpace.hasLineBreaks() = StringUtil.containsLineBreak(getText())
|
||||||
|
|
||||||
fun CharSequence.trailingLineBreakCount(): Int {
|
fun CharSequence.trailingLineBreakCount(): Int {
|
||||||
val index = ((length()-1 downTo 0).firstOrNull { val c = this[it]; c != '\n' && c != '\r' } ?: -1) + 1
|
var i = length() - 1
|
||||||
if (index == length()) return 0
|
while (i >= 0 && this[i] == '\n') {
|
||||||
return StringUtil.getLineBreakCount(subSequence(index, length()))
|
i--
|
||||||
|
}
|
||||||
|
return length() - i - 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user