File tree Expand file tree Collapse file tree 3 files changed +46
-0
lines changed
Expand file tree Collapse file tree 3 files changed +46
-0
lines changed Original file line number Diff line number Diff line change 6767 ],
6868 "key" : " 9"
6969 }
70+ ],
71+ "file-explorer:move-file" : [
72+ {
73+ "modifiers" : [
74+ " Mod" ,
75+ " Shift"
76+ ],
77+ "key" : " M"
78+ }
7079 ]
7180}
File renamed without changes.
Original file line number Diff line number Diff line change 1+ ---
2+ title : Kotlin inline
3+ description :
4+ aliases : []
5+ date : 2025-09-02
6+ tags : [Kotlin]
7+ comments : true
8+ ---
9+ # Kotlin inline
10+ ## 배경
11+ - [[ 고차 함수]] 를 사용하면 특정한 런타임 페널티가 발생할 수 있다.
12+ - 각 함수는 객체이며, [[Closure]]를 캡처하기 때문이다.
13+ - 함수 객체와 클래스에 대한 메모리 할당, 그리고 가상 호출은 런타임에서 오버헤드를 유발한다.
14+ - 그렇기 때문에 이런 오버헤드는 ** 람다 표현식을 인라인 처리함으로써 제거할 수 있다.**
15+
16+ ## 예시
17+ ``` kotlin
18+ # 함수형으로 선언된 예시
19+ lock(l) { foo() }
20+
21+ # 컴파일가 아래 형태로 최적화한 예시
22+ l.lock()
23+ try {
24+ foo()
25+ } finally {
26+ l.unlock()
27+ }
28+ ```
29+ - 코틀린에서 ` inline ` 키워드를 사용하면 실제로 호출 지점에 ** 직접 삽입(inline)** 한다.
30+ - 그렇지만 너무 큰 함수에 inline을 사용하는건 성능상으로 이득을 볼 수 없는 주의해야 한다.
31+
32+ ## See Also
33+ - [[ Kotlin reified type parameter]]
34+
35+ ## Reference
36+ - https://kotlinlang.org/docs/inline-functions.html
37+
You can’t perform that action at this time.
0 commit comments