Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc2b73df

Browse files
committed
Use pointers for retrieving a config entry
This avoids a copy of the struct when we only want to grab the stringsto convert them to managed strings.
1 parentb1f1f47 commitc2b73df

File tree

6 files changed

+21
-50
lines changed

6 files changed

+21
-50
lines changed

‎LibGit2Sharp/Configuration.cs‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -732,13 +732,12 @@ private IEnumerable<ConfigurationEntry<string>> BuildConfigEntries()
732732
returnProxy.git_config_foreach(configHandle,BuildConfigEntry);
733733
}
734734

735-
privatestaticConfigurationEntry<string>BuildConfigEntry(IntPtrentryPtr)
735+
privatestaticunsafeConfigurationEntry<string>BuildConfigEntry(IntPtrentryPtr)
736736
{
737-
varentry=entryPtr.MarshalAs<GitConfigEntry>();
738-
739-
returnnewConfigurationEntry<string>(LaxUtf8Marshaler.FromNative(entry.namePtr),
740-
LaxUtf8Marshaler.FromNative(entry.valuePtr),
741-
(ConfigurationLevel)entry.level);
737+
varentry=(GitConfigEntry*)entryPtr.ToPointer();
738+
returnnewConfigurationEntry<string>(LaxUtf8Marshaler.FromNative(entry->namePtr),
739+
LaxUtf8Marshaler.FromNative(entry->valuePtr),
740+
(ConfigurationLevel)entry->level);
742741
}
743742

744743
/// <summary>

‎LibGit2Sharp/Core/GitConfigEntry.cs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
namespaceLibGit2Sharp.Core
55
{
66
[StructLayout(LayoutKind.Sequential)]
7-
internalstructGitConfigEntry
7+
internalunsafestructGitConfigEntry
88
{
9-
publicIntPtrnamePtr;
10-
publicIntPtrvaluePtr;
9+
publicchar*namePtr;
10+
publicchar*valuePtr;
1111
publicuintlevel;
12-
publicIntPtrfreePtr;
13-
publicIntPtrpayloadPtr;
12+
publicvoid*freePtr;
13+
publicvoid*payloadPtr;
1414
}
1515
}

‎LibGit2Sharp/Core/Handles/GitConfigEntryHandle.cs‎

Lines changed: 0 additions & 16 deletions
This file was deleted.

‎LibGit2Sharp/Core/NativeMethods.cs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,11 +348,11 @@ internal static extern int git_config_delete_multivar(
348348
internalstaticexternvoidgit_config_free(IntPtrcfg);
349349

350350
[DllImport(libgit2)]
351-
internalstaticexternvoidgit_config_entry_free(IntPtrentry);
351+
internalstaticexternunsafevoidgit_config_entry_free(GitConfigEntry*entry);
352352

353353
[DllImport(libgit2)]
354-
internalstaticexternintgit_config_get_entry(
355-
outGitConfigEntryHandleentry,
354+
internalstaticexternunsafeintgit_config_get_entry(
355+
outGitConfigEntry*entry,
356356
ConfigurationSafeHandlecfg,
357357
[MarshalAs(UnmanagedType.CustomMarshaler,MarshalCookie=UniqueId.UniqueIdentifier,MarshalTypeRef=typeof(StrictUtf8Marshaler))]stringname);
358358

‎LibGit2Sharp/Core/Proxy.cs‎

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -473,42 +473,31 @@ public static void git_config_free(IntPtr config)
473473
NativeMethods.git_config_free(config);
474474
}
475475

476-
publicstaticvoidgit_config_entry_free(IntPtrentry)
476+
publicstaticunsafeConfigurationEntry<T>git_config_get_entry<T>(ConfigurationSafeHandleconfig,stringkey)
477477
{
478-
NativeMethods.git_config_entry_free(entry);
479-
}
480-
481-
publicstaticConfigurationEntry<T>git_config_get_entry<T>(ConfigurationSafeHandleconfig,stringkey)
482-
{
483-
GitConfigEntryHandlehandle=null;
484-
485478
if(!configurationParser.ContainsKey(typeof(T)))
486479
{
487480
thrownewArgumentException(string.Format(CultureInfo.InvariantCulture,"Generic Argument of type '{0}' is not supported.",typeof(T).FullName));
488481
}
489482

490-
GitConfigEntryentry;
491-
483+
GitConfigEntry*entry=null;
492484
try
493485
{
494-
varres=NativeMethods.git_config_get_entry(outhandle,config,key);
486+
varres=NativeMethods.git_config_get_entry(outentry,config,key);
495487
if(res==(int)GitErrorCode.NotFound)
496488
{
497489
returnnull;
498490
}
499491

500492
Ensure.ZeroResult(res);
501-
502-
entry=handle.MarshalAsGitConfigEntry();
493+
returnnewConfigurationEntry<T>(LaxUtf8Marshaler.FromNative(entry->namePtr),
494+
(T)configurationParser[typeof(T)](LaxUtf8Marshaler.FromNative(entry->valuePtr)),
495+
(ConfigurationLevel)entry->level);
503496
}
504497
finally
505498
{
506-
handle.SafeDispose();
499+
NativeMethods.git_config_entry_free(entry);
507500
}
508-
509-
returnnewConfigurationEntry<T>(LaxUtf8Marshaler.FromNative(entry.namePtr),
510-
(T)configurationParser[typeof(T)](LaxUtf8Marshaler.FromNative(entry.valuePtr)),
511-
(ConfigurationLevel)entry.level);
512501
}
513502

514503
publicstaticConfigurationSafeHandlegit_config_new()
@@ -593,7 +582,7 @@ public static ICollection<TResult> git_config_foreach<TResult>(
593582
returngit_foreach(resultSelector, c=>NativeMethods.git_config_foreach(config,(e,p)=>c(e,p),IntPtr.Zero));
594583
}
595584

596-
publicstaticIEnumerable<ConfigurationEntry<string>>git_config_iterator_glob(
585+
publicstaticunsafeIEnumerable<ConfigurationEntry<string>>git_config_iterator_glob(
597586
ConfigurationSafeHandleconfig,
598587
stringregexp,
599588
Func<IntPtr,ConfigurationEntry<string>>resultSelector)

‎LibGit2Sharp/LibGit2Sharp.csproj‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@
241241
<CompileInclude="Core\Handles\NullIndexSafeHandle.cs" />
242242
<CompileInclude="Core\ILazy.cs" />
243243
<CompileInclude="Core\LazyGroup.cs" />
244-
<CompileInclude="Core\Handles\GitConfigEntryHandle.cs" />
245244
<CompileInclude="Core\Proxy.cs" />
246245
<CompileInclude="Credentials.cs" />
247246
<CompileInclude="Core\TarWriter.cs" />

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp