25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-28 16:34:13 +01:00

Let jlib use "B" instead of "w" to format integers

As a small optimization, use io:format's "B" control sequence to format
integers.  We don't need to let Erlang figure out the data type if we
already know it.
This commit is contained in:
Holger Weiss 2014-12-12 23:50:03 +01:00
parent 0a19dac4fd
commit 466278fde1

View File

@ -683,18 +683,18 @@ timestamp_to_iso({{Year, Month, Day},
{Hour, Minute, Second}}, {Hour, Minute, Second}},
Timezone) -> Timezone) ->
Timestamp_string = Timestamp_string =
lists:flatten(io_lib:format("~4..0w-~2..0w-~2..0wT~2..0w:~2..0w:~2..0w", lists:flatten(io_lib:format("~4..0B-~2..0B-~2..0BT~2..0B:~2..0B:~2..0B",
[Year, Month, Day, Hour, Minute, Second])), [Year, Month, Day, Hour, Minute, Second])),
Timezone_string = case Timezone of Timezone_string = case Timezone of
utc -> "Z"; utc -> "Z";
{Sign, {TZh, TZm}} -> {Sign, {TZh, TZm}} ->
io_lib:format("~s~2..0w:~2..0w", [Sign, TZh, TZm]); io_lib:format("~s~2..0B:~2..0B", [Sign, TZh, TZm]);
{TZh, TZm} -> {TZh, TZm} ->
Sign = case TZh >= 0 of Sign = case TZh >= 0 of
true -> "+"; true -> "+";
false -> "-" false -> "-"
end, end,
io_lib:format("~s~2..0w:~2..0w", io_lib:format("~s~2..0B:~2..0B",
[Sign, abs(TZh), TZm]) [Sign, abs(TZh), TZm])
end, end,
{iolist_to_binary(Timestamp_string), iolist_to_binary(Timezone_string)}. {iolist_to_binary(Timestamp_string), iolist_to_binary(Timezone_string)}.
@ -703,7 +703,7 @@ timestamp_to_iso({{Year, Month, Day},
timestamp_to_iso({{Year, Month, Day}, timestamp_to_iso({{Year, Month, Day},
{Hour, Minute, Second}}) -> {Hour, Minute, Second}}) ->
iolist_to_binary(io_lib:format("~4..0w~2..0w~2..0wT~2..0w:~2..0w:~2..0w", iolist_to_binary(io_lib:format("~4..0B~2..0B~2..0BT~2..0B:~2..0B:~2..0B",
[Year, Month, Day, Hour, Minute, Second])). [Year, Month, Day, Hour, Minute, Second])).
-spec now_to_utc_string(erlang:timestamp()) -> binary(). -spec now_to_utc_string(erlang:timestamp()) -> binary().
@ -718,8 +718,8 @@ now_to_utc_string({MegaSecs, Secs, MicroSecs}, Precision) ->
calendar:now_to_universal_time({MegaSecs, Secs, calendar:now_to_universal_time({MegaSecs, Secs,
MicroSecs}), MicroSecs}),
FracOfSec = round(MicroSecs / math:pow(10, 6 - Precision)), FracOfSec = round(MicroSecs / math:pow(10, 6 - Precision)),
list_to_binary(io_lib:format("~4..0w-~2..0w-~2..0wT~2..0w:~2..0w:~2..0w.~*." list_to_binary(io_lib:format("~4..0B-~2..0B-~2..0BT~2..0B:~2..0B:~2..0B.~*."
".0wZ", ".0BZ",
[Year, Month, Day, Hour, Minute, Second, [Year, Month, Day, Hour, Minute, Second,
Precision, FracOfSec])). Precision, FracOfSec])).
@ -739,8 +739,8 @@ now_to_local_string({MegaSecs, Secs, MicroSecs}) ->
end, end,
{{Year, Month, Day}, {Hour, Minute, Second}} = {{Year, Month, Day}, {Hour, Minute, Second}} =
LocalTime, LocalTime,
list_to_binary(io_lib:format("~4..0w-~2..0w-~2..0wT~2..0w:~2..0w:~2..0w.~6." list_to_binary(io_lib:format("~4..0B-~2..0B-~2..0BT~2..0B:~2..0B:~2..0B.~6."
".0w~s~2..0w:~2..0w", ".0B~s~2..0B:~2..0B",
[Year, Month, Day, Hour, Minute, Second, [Year, Month, Day, Hour, Minute, Second,
MicroSecs, Sign, H, M])). MicroSecs, Sign, H, M])).