효과적으로 동일한 코드를, 성능 현명한 생산할 예정의 범위 내에 있기를 바랍니다. 이 비주얼 스튜디오 통해 분기점 쉽게 주사 가능 같은 유지 보수 및 디버깅 관점 옵션 # 1에서
훨씬 바람직하며 작은 각 라인 로직의 양으로 이해하는 것은 일반적으로 용이하다.
사실, 두 가지 옵션 사이의 행복 매체를 옹호을 부를 것이다 옵션 # 1.5 :
Dim html As String = WebBrowser.DocumentText
Dim htmlString As String = "size=" & Chr(34) & "15" & Chr(34) & " maxlength=" & Chr(34) & "40" & Chr(34) & ">"
Dim dIndex As Integer = html.IndexOf(htmlString)
If (dIndex > -1) Then
Dim lIndex As Integer = sDomain.IndexOf("<")
Dim sDomain As String = html.Substring(dIndex + 26, 20)
LblSubDomain.Text = sDomain.Substring(0, lIndex)
Else
LblSubDomain.Text = "Cannot Find Sub Domain Extension"
End If
이 코드의 적은 총 라인 수 있지만 가독성, 유지 보수 및 debuggability의 대부분을 유지하는 옵션 # 1이 제공됩니다. 여기
는 반사판을 통해 중간 언어 (IL)에 디 컴파일 코드입니다 :
참고 : MySub()
는 IL로 디 컴파일 옵션 # 1.
.method public instance void MySub() cil managed
{
.maxstack 4
.locals init (
[0] int32 num,
[1] string str,
[2] string str2,
[3] int32 num2,
[4] string str3,
[5] bool flag)
L_0000: nop
L_0001: ldarg.0
L_0002: callvirt instance class [System.Windows.Forms]System.Windows.Forms.WebBrowser WindowsApplication3.Form1::get_WebBrowser()
L_0007: callvirt instance string [System.Windows.Forms]System.Windows.Forms.WebBrowser::get_DocumentText()
L_000c: stloc.1
L_000d: ldstr "size=\"15\" maxlength=\"40\">"
L_0012: stloc.2
L_0013: ldloc.1
L_0014: ldloc.2
L_0015: callvirt instance int32 [mscorlib]System.String::IndexOf(string)
L_001a: stloc.0
L_001b: ldloc.0
L_001c: ldc.i4.m1
L_001d: cgt
L_001f: stloc.s flag
L_0021: ldloc.s flag
L_0023: brfalse.s L_0057
L_0025: ldloc.1
L_0026: ldloc.0
L_0027: ldc.i4.s 0x1a
L_0029: add.ovf
L_002a: ldc.i4.s 20
L_002c: callvirt instance string [mscorlib]System.String::Substring(int32, int32)
L_0031: stloc.s str3
L_0033: ldloc.s str3
L_0035: ldstr "<"
L_003a: callvirt instance int32 [mscorlib]System.String::IndexOf(string)
L_003f: stloc.3
L_0040: ldarg.0
L_0041: callvirt instance class [System.Windows.Forms]System.Windows.Forms.Label WindowsApplication3.Form1::get_LblSubDomain()
L_0046: ldloc.s str3
L_0048: ldc.i4.0
L_0049: ldloc.3
L_004a: callvirt instance string [mscorlib]System.String::Substring(int32, int32)
L_004f: callvirt instance void [System.Windows.Forms]System.Windows.Forms.Label::set_Text(string)
L_0054: nop
L_0055: br.s L_0069
L_0057: nop
L_0058: ldarg.0
L_0059: callvirt instance class [System.Windows.Forms]System.Windows.Forms.Label WindowsApplication3.Form1::get_LblSubDomain()
L_005e: ldstr "Cannot Find Sub Domain Extension"
L_0063: callvirt instance void [System.Windows.Forms]System.Windows.Forms.Label::set_Text(string)
L_0068: nop
L_0069: nop
L_006a: nop
L_006b: ret
}
참고 : MySub2()
은 IL로 디 컴파일 된 옵션 2입니다.
.method public instance void MySub2() cil managed
{
.maxstack 6
.locals init (
[0] bool flag)
L_0000: nop
L_0001: ldarg.0
L_0002: callvirt instance class [System.Windows.Forms]System.Windows.Forms.WebBrowser WindowsApplication3.Form1::get_WebBrowser()
L_0007: callvirt instance string [System.Windows.Forms]System.Windows.Forms.WebBrowser::get_DocumentText()
L_000c: ldstr "size=\"15\" maxlength=\"40\">"
L_0011: callvirt instance int32 [mscorlib]System.String::IndexOf(string)
L_0016: ldc.i4.m1
L_0017: cgt
L_0019: stloc.0
L_001a: ldloc.0
L_001b: brfalse.s L_008f
L_001d: ldarg.0
L_001e: callvirt instance class [System.Windows.Forms]System.Windows.Forms.Label WindowsApplication3.Form1::get_LblSubDomain()
L_0023: ldarg.0
L_0024: callvirt instance class [System.Windows.Forms]System.Windows.Forms.WebBrowser WindowsApplication3.Form1::get_WebBrowser()
L_0029: callvirt instance string [System.Windows.Forms]System.Windows.Forms.WebBrowser::get_DocumentText()
L_002e: ldarg.0
L_002f: callvirt instance class [System.Windows.Forms]System.Windows.Forms.WebBrowser WindowsApplication3.Form1::get_WebBrowser()
L_0034: callvirt instance string [System.Windows.Forms]System.Windows.Forms.WebBrowser::get_DocumentText()
L_0039: ldstr "size=\"15\" maxlength=\"40\">"
L_003e: callvirt instance int32 [mscorlib]System.String::IndexOf(string)
L_0043: ldc.i4.s 0x1a
L_0045: add.ovf
L_0046: ldc.i4.s 20
L_0048: callvirt instance string [mscorlib]System.String::Substring(int32, int32)
L_004d: ldc.i4.0
L_004e: ldarg.0
L_004f: callvirt instance class [System.Windows.Forms]System.Windows.Forms.WebBrowser WindowsApplication3.Form1::get_WebBrowser()
L_0054: callvirt instance string [System.Windows.Forms]System.Windows.Forms.WebBrowser::get_DocumentText()
L_0059: ldarg.0
L_005a: callvirt instance class [System.Windows.Forms]System.Windows.Forms.WebBrowser WindowsApplication3.Form1::get_WebBrowser()
L_005f: callvirt instance string [System.Windows.Forms]System.Windows.Forms.WebBrowser::get_DocumentText()
L_0064: ldstr "size=\"15\" maxlength=\"40\">"
L_0069: callvirt instance int32 [mscorlib]System.String::IndexOf(string)
L_006e: ldc.i4.s 0x1a
L_0070: add.ovf
L_0071: ldc.i4.s 20
L_0073: callvirt instance string [mscorlib]System.String::Substring(int32, int32)
L_0078: ldstr "<"
L_007d: callvirt instance int32 [mscorlib]System.String::IndexOf(string)
L_0082: callvirt instance string [mscorlib]System.String::Substring(int32, int32)
L_0087: callvirt instance void [System.Windows.Forms]System.Windows.Forms.Label::set_Text(string)
L_008c: nop
L_008d: br.s L_00a1
L_008f: nop
L_0090: ldarg.0
L_0091: callvirt instance class [System.Windows.Forms]System.Windows.Forms.Label WindowsApplication3.Form1::get_LblSubDomain()
L_0096: ldstr "Cannot Find Sub Domain Extension"
L_009b: callvirt instance void [System.Windows.Forms]System.Windows.Forms.Label::set_Text(string)
L_00a0: nop
L_00a1: nop
L_00a2: nop
L_00a3: ret
}
참고 : Reflector 더 이상 시험 기간 이상 무료 제품이지만, 코드의 IL을 얻을 수있는 무료 대안이있다 (ildasm
는 .NET Framework 및 ILSpy에 내장 된 도구는 오픈입니다입니다 Reflector에 대한 소스 응답이 더 이상 무료가 아님)
두 번째 버전이 더 효율적인 코드로 컴파일되는지 여부는 알 수 없지만 유지 관리해야한다면 지옥과 등 뒤로 모든 것을 저주합니다. 첫 번째 버전의 사소한 성능 저하는 가독성으로 인해 크게 상회합니다. –
나는 알고있다.개인적으로는 일단 기능을 다 끝내면 다른 곳으로 집중할 수 있도록 내 눈에 띄지 않게 배송하고 싶습니다. 크기가 작을수록 코드를 더 쉽게 탐색 할 수 있습니다. – Iniquity666