[latex3-commits] [git/LaTeX3-latex3-latex3] l3bitset-2: Combine some bitset internals (ff453d5af)

Joseph Wright joseph.wright at morningstar2.co.uk
Tue Jan 26 17:07:20 CET 2021


Repository : https://github.com/latex3/latex3
On branch  : l3bitset-2
Link       : https://github.com/latex3/latex3/commit/ff453d5af7f37d35156b0caa987fc36a7ec241e7

>---------------------------------------------------------------

commit ff453d5af7f37d35156b0caa987fc36a7ec241e7
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date:   Tue Jan 26 16:07:20 2021 +0000

    Combine some bitset internals


>---------------------------------------------------------------

ff453d5af7f37d35156b0caa987fc36a7ec241e7
 l3experimental/l3bitset/l3bitset.dtx | 203 ++++++++---------------------------
 1 file changed, 42 insertions(+), 161 deletions(-)

diff --git a/l3experimental/l3bitset/l3bitset.dtx b/l3experimental/l3bitset/l3bitset.dtx
index 7b8c014df..029fd1504 100644
--- a/l3experimental/l3bitset/l3bitset.dtx
+++ b/l3experimental/l3bitset/l3bitset.dtx
@@ -324,214 +324,95 @@
   { p , T , F , TF }
 %    \end{macrocode}
 % \end{macro}
-% \begin{macro}
-%   {
-%     \@@_set_true:Nn, \@@_gset_true:Nn
-%   }
+% \begin{macro}{\@@_set_true:Nn, \@@_gset_true:Nn, \@@_set_false:Nn, \@@_gset_false:Nn}
+% \begin{macro}{\@@_set:NNnN}
 % The internal command uses only numbers (integer expressions) for the
 % position.
 % A bit is set by either extending the string or by splitting it and
 % then inserting an $1$. It is not checked if the value was already $1$.
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_set_true:Nn #1#2
-  {
-    \int_compare:nNnT {#2} > { 0 }
-      {
-        \int_compare:nNnTF { \str_count:N #1 } < { #2 }
-          {
-            \exp_args:NNe
-            \str_put_left:Nn #1
-              { \prg_replicate:nn {  #2 - \str_count:N #1 - 1 } { 0 } }
-            \str_put_left:Nn #1 { 1 }
-          }
-          {
-            \str_set:Nx #1
-              {
-                \str_range:Nnn #1 { 1 } { -1 - (#2) }
-                1
-                \str_range:Nnn #1 { 1 - (#2) } { -1 }
-             }
-          }
-      }
-  }
+  { \@@_set:NNnN \str_set:Nx #1 {#2} 1 }
 \cs_new_protected:Npn \@@_gset_true:Nn #1#2
+  { \@@_set:NNnN \str_gset:Nx #1 {#2} 1 }
+\cs_new_protected:Npn \@@_set_false:Nn #1#2
+  { \@@_set:NNnN \str_set:Nx #1 {#2} 0 }
+\cs_new_protected:Npn \@@_gset_false:Nn #1#2
+  { \@@_set:NNnN \str_gset:Nx #1 {#2} 0 }
+\cs_new_protected:Npn \@@_set:NNnN #1#2#3#4
   {
-    \int_compare:nNnT { #2 } > { 0 }
+    \int_compare:nNnT {#3} > { 0 }
       {
-        \int_compare:nNnTF { \str_count:N #1 } < { #2 }
+        \int_compare:nNnTF { \str_count:N #2 } < {#3}
           {
-            \exp_args:NNe
-              \str_gput_left:Nn #1
-                { \prg_replicate:nn {  #2 - \str_count:N #1 - 1 } {0} }
-              \str_gput_left:Nn #1 { 1 }
+            #1 #2
+              {
+                #4
+                \prg_replicate:nn { #3 - \str_count:N #2 - 1 } { 0 }
+                #2
+              }
           }
           {
-            \str_gset:Nx #1
+             #1 #2
               {
-                \str_range:Nnn #1 {1}{-1 -(#2)}
-                1
-                \str_range:Nnn #1 {1 -(#2)}{-1}
-              }
+                \str_range:Nnn #2 { 1 } { -1 - (#3) }
+                #4
+                \str_range:Nnn #2 { 1 - (#3) } { -1 }
+             }
           }
       }
   }
 %    \end{macrocode}
 % \end{macro}
+% \end{macro}
 % \begin{macro}
 %   {
 %     \bitset_set_true:Nn, \bitset_set_true:cn,
 %     \bitset_gset_true:Nn, \bitset_gset_true:cn,
 %   }
+% \begin{macro}{\@@_set_aux:NNn}
 % The user commands must first translate the argument to an index number.
 %    \begin{macrocode}
 \cs_new_protected:Npn \bitset_set_true:Nn #1#2
-  {
-    \prop_if_in:cnTF { g_@@_ \cs_to_str:N #1 _name_prop } {#2}
-      {
-        \@@_set_true:Nn #1
-          {
-            \prop_item:cn  { g_@@_ \cs_to_str:N #1 _name_prop } {#2}
-          }
-      }
-      {
-        \regex_match:nnTF { ^[\d]+$ } {#2}
-          {
-            \@@_set_true:Nn #1 {#2}
-            \prop_gput:cnn { g_@@_ \cs_to_str:N #1 _name_prop } {#2} {#2}
-          }
-          {
-            \__kernel_msg_warning:nnxx { bitset } { bitset-unknown-name }
-              { \token_to_str:N #1 }
-              { \tl_to_str:n {#2} }
-          }
-      }
-  }
+  { \@@_set:NNn \@@_set_true:Nn #1 {#2} }
 \cs_new_protected:Npn \bitset_gset_true:Nn #1#2
+  { \@@_set:NNn \@@_gset_true:Nn #1 {#2} }
+\cs_new_protected:Npn \bitset_set_false:Nn #1#2
+  { \@@_set:NNn \@@_set_false:Nn #1 {#2} }
+\cs_new_protected:Npn \bitset_gset_false:Nn #1#2
+  { \@@_set:NNn \@@_gset_false:Nn #1 {#2} }
+\cs_new_protected:Npn \@@_set:NNn #1#2#3
   {
-    \prop_if_in:cnTF { g_@@_ \cs_to_str:N #1 _name_prop } {#2}
+    \prop_if_in:cnTF { g_@@_ \cs_to_str:N #2 _name_prop } {#3}
       {
-        \@@_gset_true:Nn #1
+        #1 #2
           {
-            \prop_item:cn{ g_@@_ \cs_to_str:N #1 _name_prop }{#2}
+            \prop_item:cn  { g_@@_ \cs_to_str:N #2 _name_prop } {#3}
           }
       }
       {
-        \regex_match:nnTF { ^[\d]+$ } {#2}
+        \regex_match:nnTF { ^[\d]+$ } {#3}
           {
-            \@@_gset_true:Nn #1 { #2}
-            \prop_gput:cnn { g_@@_ \cs_to_str:N #1 _name_prop } {#2} {#2}
+            #1 #2 {#3}
+            \prop_gput:cnn { g_@@_ \cs_to_str:N #2 _name_prop } {#3} {#3}
           }
           {
             \__kernel_msg_warning:nnxx { bitset } { bitset-unknown-name }
-              { \token_to_str:N #1 }
-              { \tl_to_str:n {#2} }
+              { \token_to_str:N #2 }
+              { \tl_to_str:n {#3} }
           }
       }
   }
 \cs_generate_variant:Nn \bitset_set_true:Nn  { c }
 \cs_generate_variant:Nn \bitset_gset_true:Nn { c }
+\cs_generate_variant:Nn \bitset_set_false:Nn  { c }
+\cs_generate_variant:Nn \bitset_gset_false:Nn { c }
 %    \end{macrocode}
 % \end{macro}
+% \end{macro}
 %
 % \begin{macro}
 %   {
-%     \@@_set_false:Nn, \@@_gset_false:Nn
-%   }
-% The internal command uses only numbers (integer expressions) for the
-% position.
-% Unsetting a bit has only to do something if the string is longer than then index.
-%    \begin{macrocode}
-\cs_new_protected:Npn \@@_set_false:Nn #1#2
- {
-   \int_compare:nNnT {#2} > { 0 }
-     {
-       \int_compare:nNnT { \str_count:N #1 } > { #2 - 1 }
-         {
-           \str_set:Nx #1
-             {
-               \str_range:Nnn #1 { 1 } { -1 - (#2) }
-                0
-               \str_range:Nnn #1 { 1 - (#2) } { -1 }
-             }
-         }
-     }
- }
-
-\cs_new_protected:Npn \@@_gset_false:Nn #1#2
- {
-   \int_compare:nNnT {#2} > { 0 }
-     {
-       \int_compare:nNnT { \str_count:N #1 } > { #2 - 1 }
-         {
-           \str_gset:Nx #1
-             {
-               \str_range:Nnn #1 { 1 } { -1 - (#2) }
-                0
-               \str_range:Nnn #1 { 1 - (#2) } { -1 }
-             }
-         }
-     }
- }
-%    \end{macrocode}
-%  \end{macro}
-
-% \begin{macro}
-%   {
-%     \bitset_set_false:Nn,  \bitset_set_false:cn,
-%     \bitset_gset_false:Nn, \bitset_gset_false:cn
-%   }
-%    \begin{macrocode}
-\cs_new_protected:Npn \bitset_set_false:Nn #1#2
- {
-    \prop_if_in:cnTF { g_@@_ \cs_to_str:N #1 _name_prop } {#2}
-      {
-        \@@_set_false:Nn #1
-          {
-            \prop_item:cn{ g_@@_ \cs_to_str:N #1 _name_prop } {#2}
-          }
-      }
-      {
-        \regex_match:nnTF { ^[\d]+$ } {#2}
-          {
-            \@@_set_false:Nn #1 { #2}
-            \prop_gput:cnn { g_@@_ \cs_to_str:N #1 _name_prop } {#2} {#2}
-          }
-          {
-            \__kernel_msg_warning:nnxx { bitset } { bitset-unknown-name }
-              { \token_to_str:N #1 }
-              { \tl_to_str:n {#2} }
-          }
-      }
- }
-
-\cs_new_protected:Npn \bitset_gset_false:Nn #1#2
- {
-   \prop_if_in:cnTF { g_@@_ \cs_to_str:N #1 _name_prop } {#2}
-     {
-       \@@_gset_false:Nn #1
-         {
-           \prop_item:cn{ g_@@_ \cs_to_str:N #1 _name_prop } {#2}
-         }
-     }
-     {
-       \regex_match:nnTF { ^[\d]+$ } {#2}
-         {
-           \@@_gset_false:Nn #1 { #2}
-           \prop_gput:cnn { g_@@_ \cs_to_str:N #1 _name_prop } {#2} {#2}
-         }
-         {
-           \__kernel_msg_warning:nnxx { bitset } { bitset-unknown-name }
-             { \token_to_str:N #1 }
-             { \tl_to_str:n {#2} }
-         }
-     }
- }
-\cs_generate_variant:Nn \bitset_set_false:Nn { c }
-\cs_generate_variant:Nn \bitset_gset_false:Nn { c }
-%    \end{macrocode}
-%  \end{macro}
-% \begin{macro}
-%   {
 %     \bitset_clear:N,  \bitset_clear:c,
 %     \bitset_gclear:N, \bitset_gclear:c
 %   }





More information about the latex3-commits mailing list.