Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
Dapper
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
Dapper
Commits
95f5f9a2
Commit
95f5f9a2
authored
Oct 22, 2014
by
Marc Gravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
re-use StringBuilder instances when possible
parent
d9f2801f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
10 deletions
+61
-10
SqlMapper.cs
Dapper NET40/SqlMapper.cs
+45
-10
Tests.cs
Tests/Tests.cs
+16
-0
No files found.
Dapper NET40/SqlMapper.cs
View file @
95f5f9a2
...
@@ -2364,7 +2364,7 @@ public bool TryGetValue(string name, out object value)
...
@@ -2364,7 +2364,7 @@ public bool TryGetValue(string name, out object value)
public
override
string
ToString
()
public
override
string
ToString
()
{
{
var
sb
=
new
StringBuilder
(
"{DapperRow"
);
var
sb
=
GetStringBuilder
().
Append
(
"{DapperRow"
);
foreach
(
var
kv
in
this
)
foreach
(
var
kv
in
this
)
{
{
var
value
=
kv
.
Value
;
var
value
=
kv
.
Value
;
...
@@ -2379,7 +2379,7 @@ public override string ToString()
...
@@ -2379,7 +2379,7 @@ public override string ToString()
}
}
}
}
return
sb
.
Append
(
'}'
).
ToString
();
return
sb
.
Append
(
'}'
).
__ToStringRecycle
();
}
}
System
.
Dynamic
.
DynamicMetaObject
System
.
Dynamic
.
IDynamicMetaObjectProvider
.
GetMetaObject
(
System
.
Dynamic
.
DynamicMetaObject
System
.
Dynamic
.
IDynamicMetaObjectProvider
.
GetMetaObject
(
...
@@ -2752,21 +2752,21 @@ public static void PackListParameters(IDbCommand command, string namePrefix, obj
...
@@ -2752,21 +2752,21 @@ public static void PackListParameters(IDbCommand command, string namePrefix, obj
// looks like an optimize hint; expand it
// looks like an optimize hint; expand it
var
suffix
=
match
.
Groups
[
2
].
Value
;
var
suffix
=
match
.
Groups
[
2
].
Value
;
var
sb
=
new
StringBuilder
(
variableName
).
Append
(
1
).
Append
(
suffix
);
var
sb
=
GetStringBuilder
().
Append
(
variableName
).
Append
(
1
).
Append
(
suffix
);
for
(
int
i
=
2
;
i
<=
count
;
i
++)
for
(
int
i
=
2
;
i
<=
count
;
i
++)
{
{
sb
.
Append
(
','
).
Append
(
variableName
).
Append
(
i
).
Append
(
suffix
);
sb
.
Append
(
','
).
Append
(
variableName
).
Append
(
i
).
Append
(
suffix
);
}
}
return
sb
.
ToString
();
return
sb
.
__ToStringRecycle
();
}
}
else
else
{
{
var
sb
=
new
StringBuilder
(
"("
).
Append
(
variableName
).
Append
(
1
);
var
sb
=
GetStringBuilder
().
Append
(
'('
).
Append
(
variableName
).
Append
(
1
);
for
(
int
i
=
2
;
i
<=
count
;
i
++)
for
(
int
i
=
2
;
i
<=
count
;
i
++)
{
{
sb
.
Append
(
','
).
Append
(
variableName
).
Append
(
i
);
sb
.
Append
(
','
).
Append
(
variableName
).
Append
(
i
);
}
}
return
sb
.
Append
(
')'
).
ToString
();
return
sb
.
Append
(
')'
).
__ToStringRecycle
();
}
}
});
});
}
}
...
@@ -2862,12 +2862,20 @@ public static string Format(object value)
...
@@ -2862,12 +2862,20 @@ public static string Format(object value)
var
multiExec
=
GetMultiExec
(
value
);
var
multiExec
=
GetMultiExec
(
value
);
if
(
multiExec
!=
null
)
if
(
multiExec
!=
null
)
{
{
var
sb
=
new
StringBuilder
()
;
StringBuilder
sb
=
null
;
bool
first
=
true
;
bool
first
=
true
;
foreach
(
object
subval
in
multiExec
)
foreach
(
object
subval
in
multiExec
)
{
{
sb
.
Append
(
first
?
'('
:
','
).
Append
(
Format
(
subval
));
if
(
first
)
first
=
false
;
{
sb
=
GetStringBuilder
().
Append
(
'('
);
first
=
false
;
}
else
{
sb
.
Append
(
','
);
}
sb
.
Append
(
Format
(
subval
));
}
}
if
(
first
)
if
(
first
)
{
{
...
@@ -2875,7 +2883,7 @@ public static string Format(object value)
...
@@ -2875,7 +2883,7 @@ public static string Format(object value)
}
}
else
else
{
{
return
sb
.
Append
(
')'
).
ToString
();
return
sb
.
Append
(
')'
).
__ToStringRecycle
();
}
}
}
}
throw
new
NotSupportedException
(
value
.
GetType
().
Name
);
throw
new
NotSupportedException
(
value
.
GetType
().
Name
);
...
@@ -4327,6 +4335,33 @@ public static string GetTypeName(this DataTable table)
...
@@ -4327,6 +4335,33 @@ public static string GetTypeName(this DataTable table)
{
{
return
table
==
null
?
null
:
table
.
ExtendedProperties
[
DataTableTypeNameKey
]
as
string
;
return
table
==
null
?
null
:
table
.
ExtendedProperties
[
DataTableTypeNameKey
]
as
string
;
}
}
// one per thread
[
ThreadStatic
]
private
static
StringBuilder
perThreadStringBuilderCache
;
private
static
StringBuilder
GetStringBuilder
()
{
var
tmp
=
perThreadStringBuilderCache
;
if
(
tmp
!=
null
)
{
perThreadStringBuilderCache
=
null
;
tmp
.
Length
=
0
;
return
tmp
;
}
return
new
StringBuilder
();
}
private
static
string
__ToStringRecycle
(
this
StringBuilder
obj
)
{
if
(
obj
==
null
)
return
""
;
var
s
=
obj
.
ToString
();
if
(
perThreadStringBuilderCache
==
null
)
{
perThreadStringBuilderCache
=
obj
;
}
return
s
;
}
}
}
/// <summary>
/// <summary>
...
...
Tests/Tests.cs
View file @
95f5f9a2
...
@@ -3178,7 +3178,23 @@ public void DataTableParameters()
...
@@ -3178,7 +3178,23 @@ public void DataTableParameters()
ex
.
Message
.
Equals
(
"The table type parameter 'ids' must have a valid type name."
);
ex
.
Message
.
Equals
(
"The table type parameter 'ids' must have a valid type name."
);
}
}
}
}
public
void
SO26468710_InWithTVPs
()
{
// this is just to make it re-runnable; normally you only do this once
try
{
connection
.
Execute
(
"drop type MyIdList"
);
}
catch
{
}
connection
.
Execute
(
"create type MyIdList as table(id int);"
);
DataTable
ids
=
new
DataTable
{
Columns
=
{{
"id"
,
typeof
(
int
)}},
Rows
=
{{
1
},{
3
},{
5
}}
};
ids
.
SetTypeName
(
"MyIdList"
);
int
sum
=
connection
.
Query
<
int
>(
@"
declare @tmp table(id int not null);
insert @tmp (id) values(1), (2), (3), (4), (5), (6), (7);
select * from @tmp t inner join @ids i on i.id = t.id"
,
new
{
ids
}).
Sum
();
sum
.
IsEqualTo
(
9
);
}
public
void
DataTableParametersWithExtendedProperty
()
public
void
DataTableParametersWithExtendedProperty
()
{
{
try
{
connection
.
Execute
(
"drop proc #DataTableParameters"
);
}
catch
{
}
try
{
connection
.
Execute
(
"drop proc #DataTableParameters"
);
}
catch
{
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment