Consider the thermal issues. I don't know what you think your actual maximum current might be, but lets say it is 300mA and you have an actual 12VDC regulated supply as an input. The regulator will have to dissipate (0.3 * (Vin - Vout - Vf)). Assuming the input is 12, the output 5 and the diode's Vf is 0.6V, you have 0.3 * 6.4 or 1.92 watts. A plain TO-220 LM7805 can handle that without a heatsink. A heatsink is a part too! I'm assuming you are making something one-off and that this is not a a production project.
Is LM78M05 able to dissipate less heat than LM7805? I haven't found this info in the datasheet.
The maximum power dissipation depends on many factors: maximum allowable die/junction temperature, ambient temperature, package and heat sinking.
The thermal resitance between the die and the ambient, i.e. surroundings, govens how much the temperature of the die will increase, given a certain power dissipation. It's equal to the sum of the thermal resistance between the die, case, any thermal tab used and heatsink.
Example:
If the thermal resistance between the die and ambient is 25°C/W, the maximum operating temperature is 50°C and the maximum die temperature is 150°C/W. The maximum permissible temperature rise is 150 - 50 = 100°C/W, giving a maximum power dissipation of 100/25 = 4W.
Looking at the data sheets for the LM78M05 and LM7805, for the TO220 packages, the LM78M05 has a lower junction to case thermal resistance of 1.3°C/W vs 1.7°C/W of the LM7805, but a lower maximum junction temperature of 125°C, vs 150°C for the LM7805.
https://www.ti.com/lit/ds/symlink/lm340.pdfhttps://www.ti.com/lit/ds/snvs090g/snvs090g.pdfOne thing I often do, when I only have the LM7805 available and I need it in a relatively low current application, is add a series resistor to limit the current. Suppose my circuit needs 100mA maximum, the minimum power supply voltage is 10V and the lowest voltage I want at the LM7805's input is 8V. That gives a maximum voltage drop accross the resistor of 10 - 8 = 2V, applying Ohm's law gives V/I = 2/0.1 = 20 Ohms. If the regulator's output is shorted, when the supply voltage is at its nominal 12V, the LM7805 will probably drop around 2V, giving 10V accross the resistor and a short circuit current of 500mA, rather than the 1.5A listed on the LM7805 data sheet. The resistor will need to be rated to dissipate 5W. There should be a fairly big decoupling capacitor, say 100µF, on the LM7805's input.