Optimize Name::cutFirst and Name::cutLast
This commit is contained in:
parent
7d88f828d7
commit
f83b759e75
@ -120,12 +120,12 @@ public operator fun Name.get(i: Int): NameToken = tokens[i]
|
||||
/**
|
||||
* The reminder of the name after last element is cut. For empty name return itself.
|
||||
*/
|
||||
public fun Name.cutLast(): Name = Name(tokens.dropLast(1))
|
||||
public fun Name.cutLast(): Name = Name(tokens.subList(0, tokens.size - 1))
|
||||
|
||||
/**
|
||||
* The reminder of the name after first element is cut. For empty name return itself.
|
||||
*/
|
||||
public fun Name.cutFirst(): Name = Name(tokens.drop(1))
|
||||
public fun Name.cutFirst(): Name = Name(tokens.subList(1, tokens.size))
|
||||
|
||||
public val Name.length: Int get() = tokens.size
|
||||
|
||||
|
@ -38,4 +38,16 @@ class NameTest {
|
||||
assertEquals(1, unescapedName.length)
|
||||
assertEquals(escapedName, Name.parse(escapedName.toString()))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun cutFirst() {
|
||||
val name = Name.parse("a.b.c")
|
||||
assertEquals("b.c".parseAsName(), name.cutFirst())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun cutLast() {
|
||||
val name = Name.parse("a.b.c")
|
||||
assertEquals("a.b".parseAsName(), name.cutLast())
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user